-
Hello, i was jsut wondering, i am making a loggin program to a bigger program, but i have no idea how to make it so they can choose a Password and Username...how would i do such a thing? If u know the answer please post:D
THanks for listening
-
why not just make it so that it stores the user name and passsword on the computer?
-
Store the username and password in the Registry. For additional security, you can encrypt them.
-
I'm not sure about using the Registry. Never really used it, but here is how to do it using an INI file.
Code:
Public Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Public Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String
Dim strbuffer As String
Let strbuffer$ = String$(750, Chr$(0&))
Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
End Function
Public Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
End Sub
'We will use Combo boxes as name and password.
'Combo1.text = name
'Combo2.text = password
Private Sub Form_Load()
Combo1.text = readini("UserPW.ini", "User", "C:\Windows\UserPW.ini")
Combo2.text = readini("UserPW.ini", "Password", "C:\Windows\UserPW.ini")
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call writeini("UserPW.ini", "User", "" & Combo1.text & "", "C:\Windows\UserPW.ini")
Call writeini("UserPW.ini", "Password", "" & Combo2.text & "", "C:\Windows\UserPW.ini")
End Sub
'If there are multiple users:
Public Sub List_Save(TheList As ComboBox, FileName As String)
On Error Resume Next
Dim Save As Long
Dim fFile As Integer
fFile = FreeFile
Open FileName For Output As fFile
For Save = 0 To TheList.ListCount - 1
Print #fFile, TheList.List(Save)
Next Save
Close fFile
End Sub
'Call List_Save(Combo1, "C:\Windows\UserPW.txt")
'Call List_Save(Combo2, "C:\Windows\UserPW.txt")
Public Sub List_Add(List As ComboBox, txt As String)
List.AddItem txt
End Sub
'Call List_Add(Combo1, "User")
Public Sub List_Load(TheList As ComboBox, FileName As String)
On Error Resume Next
Dim TheContents As String
Dim fFile As Integer
fFile = FreeFile
Open FileName For Input As fFile
Do
Line Input #fFile, TheContents$
Call List_Add(TheList, TheContents$)
Loop Until EOF(fFile)
Close fFile
End Sub
'Call List_Load(Combo1, "C:\Windows\UserPW.txt")
'Call List_Load(Combo2, "C:\Windows\UserPW.txt")
Remember, this is just an example. I suggest you do as Megatron said and store it in the Registry.
Get the point? Hope that helps.
[Edited by Matthew Gates on 08-10-2000 at 07:48 PM]
-
Here's a sample project: http://www.parksie.uklinux.net/registry.zip
[Edited by parksie on 08-10-2000 at 08:53 PM]
-
Thanks Guys!
Thanks everyone for the help!