Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Password...

Status
Not open for further replies.

acknowledge

Technical User
Apr 22, 2002
5
TH
I would like to know how to creat a access box which has user name and password in such a manner that many programs have.
Thank you very much.
 
Hi,

Use 2 textboxes. Set the .passwordchar of one of them to * (or what ever character you want to use).
You also need a way of validating the username / password. Depends on the use of you program you could hardcode it into the source or put it in a database.
Sunaj
'The gap between theory and practice is not as wide in theory as it is in practice'
 
HI,

I made at password program last week.
I have 2 textboxes. onw for username and one for password.
I have the username/passwords on the windows registry.
so when he enters the username it loads the string for the key ("HKey_CurrentUser\whaterver\theusername")

privat sub command1_click()
dim pass as string
(Hkey_Current_user) (the textbox for the username)
pass = readkey ("HKCU\software\whatever\" & username.text)
if pass = password.text then
msgbox "Correct!"
else
msgbox "Invalid password", vbcritical
end if

end sub ken Christensen
Ken@Christensen.dk
Ken Christensen Software
 
Generally, it isn't a good idea to expose a password by saving it in the registry or a file. A better option is to save a "hash" value. This is a pseudo-random value calculated from the password. In order for somebody to discover the original password they either need to know the exact method used to generate the "hash" and have the patience required to find the password that generates it... or they have to be a very good guesser (in which case, the scheme is utterly useless).

Add two text boxes and a command button to a form in order to see how this works. Type a password in the first text box, type another password in the second text box and click the command button. The code will tell you whether or not the two passwords match, based on the "hash" values they generate.
Code:
Dim OriginalHash As String
Dim OriginalSeed As Long
Dim NewHash As String
Dim NewSeed As Long

Private Sub Text1_LostFocus()
OriginalSeed = 0
OriginalHash = ""
For Re = 1 To Len(Text1.Text)
    OriginalSeed = OriginalSeed + (Asc(Mid$(Text1.Text, Re, 1)) * (1 ^ (Re - 1)))
Next
a = -Rnd(-1)
Randomize OriginalSeed
For Re = 1 To 255
    OriginalHash = OriginalHash & Chr$(Int(90 * Rnd + 33))
Next
End Sub

Private Sub Command1_Click()
NewSeed = 0
NewHash = ""
For Re = 1 To Len(Text3.Text)
    NewSeed = NewSeed + (Asc(Mid$(Text3.Text, Re, 1)) * (1 ^ (Re - 1)))
Next
a = -Rnd(-1)
Randomize NewSeed
For Re = 1 To 255
    NewHash = NewHash & Chr$(Int(90 * Rnd + 33))
Next
If OriginalHash = NewHash Then
    MsgBox "Passwords match"
Else
    MsgBox "Incorrect password"
End If
End Sub
VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top