|
-
Nov 26th, 2000, 08:33 AM
#1
Thread Starter
Junior Member
Hi everybody
I recently created a small vb prog and used the vb login form to open the prog via a password that is predefined in the code. What i'm after is a way of letting the user enter and set their own password. Can anyone help?
Thanks
-
Nov 26th, 2000, 08:38 AM
#2
Fanatic Member
The best way, is by not hardcoding the password. Store it somewhere in a file.
To write the password to a file:
Code:
Dim Password As String 'the pw
Password = "top-secret"
'open the file
Open "c:\myfile.txt" For Output As #1
'write it
Print #1,,Password
'close the file
Close #1
To read the password from a file:
Code:
Dim Password As String 'the pw
'open the file
Open "c:\myfile.txt" For Input As #1
'read it
Line Input #1,,Password
'close the file
Close #1
But now, the password is readable for everybody who opens the file. In a few minutes, I'll post a way to encrypt the password a little.
-
Nov 26th, 2000, 08:41 AM
#3
Fanatic Member
This code is for encryption/decryption.
Code:
Function Crypt(Data As String) As String
Dim oneByte As String ' a swap variable
Dim Output As String ' the output
For i = 1 To Len(Data) 'loop trough all the bytes
oneByte = Right(Left(Data, i), 1) ' get a byte
oneByte = Chr((Int(Asc(oneByte)) Xor 152)) ' encrypt the byte
Output = Output & oneByte ' add it to the output
Next
Crypt = Output ' return the encrypted or decrypted data
End Function
If you give it a string, it will encrypt it. If you give it an encrypted string, it will decrypt it.
Note that this way of encryption is not very secure. Everybody with some HEX-editor experience can crack it, but the average user can't crack it.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|