Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
hi everybody,
There are some code components with hardcoded passwords. That needs to
be changed to be picked from an INI file. Also, there needs to be a method
wherein every 30 days once or some time period scheduled, the passwords
should be changed by prompting the user.can u explain what is it expected from the above.Also explain me what is hardcoded?
Thx
Nanda

Sounds like homework.
Here is the idea. Hardcoding puts the password in
the code.Ex.
input password
If password = "12547892" then runcode
else print "BAD CODE"
notice that doing something like that is not very
secure.

Nanda,
Hardcoding means placing literals inside code. For instance, if I were to hardcode a password, I might do something like this:
If Password = "PA$$WORD" Then...
opposite of hardcoding is using variables, which are dynamic and not static, as in the string literal above...
If Password = StoredPassword Then...
Your program wants to elliminate the hardcoded password with ones that are selected from an INI file.
To do this, you will need to keep track of the last time the password was changed (so that you can prompt the user in 30 days), and also load the ini file into a data member that can be used to verify passwords/store new password/save password list.
Personally I suggest one of two ways:
1) Structured Array: This is where you create an array of a structure, or a type (in vb)
2) Collection: This is where you create a collection of a specific type.
Both allow for dynamic allocation of memory (as long as you code for it) and both are quite effective. The Collection might be slightly harder to code and understand if you are a newbie to vb (hey I made a rhyme) so I will only show the Structure Array method. If you want to see the collection code, let me know.
Using a Structure Array would be like this:
Private Type INIFileStruct
UserName As String
Password As String
CreationDate as String
End Type
Dim INIFileRecord() AS INIFIleStructThen when you load them from the file (one at a time) you can dynamically allocate space:
Private Function LoadINIFile(ByVal FileSpec as String) As Long
Dim Count As Long
Dim TempString As String
Dim FSO As Object
Dim FileID As Long
Set FSO = CreateObject("Scripting.FileSystemObject")
If FSO.FileExists(FileSpec) Then
Count = 0
FileID = FreeFile()
Open FileSpec For Input As #FileID
Do While Not EOF(#FileID)
ReDim Preserve INIFileRecord(Count +1) As INIFileStruct
Line Input #FileID, TempString
' Assume the INIFile Integrity is USERNAME|PASSWORD|DATECREATED, this will depend on how you code it, actually.
INIFileRecord(Count).UserName = Left(TempString,InStr(1,TempString,"|")-1)
TempString = Mid(TempString,InStr(1,TempString,"\") + 1, Len(TempString))
INIFileRecord(Count).Password = Left(TempString,InStr(1,TempString,"|")-1)
INIFileRecord(Count).CreationDate = Mid(TempString,InStr(1,TempString,"\") + 1, Len(TempString))
Count = Count + 1
DoEvents ' This allows your program to talk with windows
Loop
End If
LoadINIFile = Count ' Return the number of records read
End FunctionNow, just reverse the process to save the INI file, and use the individual elements to verify the username/password or to modify the password when DateDiff("d",INIFileRecord(CurrentRecordID).CreationDate,Date)) > 29
Hope this helps
Chi Happens

Hi,
Thank u so much Chi Happen for u r effort.
I would like to another method also:Collection
thx
N_a_n_d_a.R

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |