Computing.Net > Forums > Programming > In VB,what is password hardcoding?

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

In VB,what is password hardcoding?

Reply to Message Icon

Name: N_a_n_d_a.R
Date: October 30, 2003 at 03:16:25 Pacific
OS: Win 2000
CPU/Ram: P iv
Comment:

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



Sponsored Link
Ads by Google

Response Number 1
Name: JasonR
Date: October 30, 2003 at 04:10:05 Pacific
Reply:

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.


0

Response Number 2
Name: Chi Happens
Date: October 30, 2003 at 04:22:53 Pacific
Reply:

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 INIFIleStruct

Then 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 Function

Now, 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


0

Response Number 3
Name: Anusha.R
Date: November 5, 2003 at 02:12:55 Pacific
Reply:

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


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: In VB,what is password hardcoding?

? in c++...what is this? www.computing.net/answers/programming/-in-cwhat-is-this/3311.html

StuartS...DLL in C++ for use in VB? www.computing.net/answers/programming/stuartsdll-in-c-for-use-in-vb/12545.html

What is VB.NET? www.computing.net/answers/programming/what-is-vbnet/880.html