The extent of my abilities is saving/reading text to and from a text file but that would defeat the purpose of implementing passwords. Could someone tell me how I can save the password in a more secure file? A simpe sample would be nice. Thanks.
Printable View
The extent of my abilities is saving/reading text to and from a text file but that would defeat the purpose of implementing passwords. Could someone tell me how I can save the password in a more secure file? A simpe sample would be nice. Thanks.
Encrypt the file. Do a search on file encryption, there are infinate examples
I considered that but i thought it would be too much effort if the file is just gonna contain 1 password (8-12 characters) and nothing else. I was hoping for another solution. It doesnt have to be very secure, just as long as it cant be opened with just a text file viewer and is updatable so the password can be changed.
Here's an encryption/ Decryption function
VB Code:
'General Declerations Const Public_Key = "Test178uy" Const Private_Key = "$45rt8" Public strDecrypted As String Public strEncrypted As String Public Function Crypto(InString As String, PrivateKey As String, PublicKey As String) As String Dim myIN, myKEY As String, myC As String, myPub As String Dim KeyList() As Byte Dim PubList() As Byte Dim I As Long, J As Long, k As Long myIN = InString myKEY = PrivateKey myPub = PublicKey ReDim KeyList(Len(myKEY)) ReDim PubList(Len(myPub)) For I = 1 To Len(myKEY) KeyList(I) = Asc(Mid(myKEY, I, 1)) Next I For I = 1 To Len(myPub) PubList(I) = Asc(Mid(myPub, I, 1)) Next I J = 1 k = 1 For I = 1 To Len(myIN) myC = myC & Chr((Asc(Mid(myIN, I, 1)) Xor KeyList(J)) Xor PubList(k)) If J = Len(myKEY) Then J = 0 If k = Len(myPub) Then k = 0 J = J + 1 k = k + 1 Next I Crypto = myC End Function
Use it like this:
You could save the encrypted username & passwords in a text file..and then call it back or you could save it in the Windows Registry as well...VB Code:
Private Sub Comman1_Click() strEncryption = Crypto("My Password", Private_Key, Public_Key) 'This will encrypt My Password. to Decrypt strDecryption=Crypto(strEncrypted, Private_Key, Public_Key) MsgBox strDecryption End Sub
Guess i'll go with the encrypt/decrypt plan then. Thanks for including the implementation of pub/priv keys in your sample.
mxnmx's example is a basic XOR algorithm, and the public and private key is placed in error there.... that's defenitly not how your supposed to use a public and private key...
Here's how the encryption/decryption SHOULD be with public and private keys:
First of all you use one at the time...
To encrypt, you use the public key, and you are NOT able to decrypt with the public key, ONLY encrypt
To decrypt, you use the private key, and the private key is used for decryption ONLY !
If you wander why ?
Let's say you have a group of friends, and you want to exchange data in a safe way (encryption), you give the public key to your friends, they encrypt the data, send it to a server (for example), and since only you have the private key, only you can decrypt the data. And if you want to send data back, you need their public key(s), and so on...
In the example given there, they are both used when encrypting AND decryption of the string witch is wrong...
In the example, a correct variable name would be, password1 and password2, because that's what it does... it's using 2 passwords to encrypt and decrypt
To prove my point go to this link, and scroll to "Public-Key Encryption"
http://developer.netscape.com/docs/m...n/contents.htm