473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Encrypting Password

Hi!I am doing a login form but i have this problem I want to encrypt the password they entered and save it in database..Can someone help me?Thank You in Advance..


-cassey
Jan 24 '07 #1
14 13569
ADezii
8,834 Expert 8TB
Hi!I am doing a login form but i have this problem I want to encrypt the password they entered and save it in database..Can someone help me?Thank You in Advance..


-cassey
I'll look up a simple encryption algorithm as soon as I get a chance and post it for you.
Jan 24 '07 #2
NeoPa
32,556 Expert Mod 16PB
This is a very basic one that I use.
Expand|Select|Wrap|Line Numbers
  1. 'If I told you what this did I'd have to kill you.
  2. Public Function Scramble(strPW As String)
  3.     Dim intIdx As Integer
  4.  
  5.     Scramble = strPW
  6.     For intIdx = 1 To Len(strPW)
  7.         Mid(Scramble, intIdx, 1) = _
  8.             Chr(&H40 Or (Not Asc(Mid(strPW, intIdx, 1))) And &H3F)
  9.     Next intIdx
  10. End Function
I expect the ADezii comes up with will be less predictable.
Jan 24 '07 #3
ADezii
8,834 Expert 8TB
Hi!I am doing a login form but i have this problem I want to encrypt the password they entered and save it in database..Can someone help me?Thank You in Advance..


-cassey
As promised, any questions feel free to ask:
Expand|Select|Wrap|Line Numbers
  1. Public Function fEncryptString(TheString As String, ByVal nbrPlaces As Byte) As String
  2. '*******************************
  3. ' Author: Philfr               *
  4. ' Email : philfrank@yahoo.com  *
  5. ' Date  : 25 - 5 - 02          *
  6. '******************************************************************************************
  7. 'This is a simple Encryption Algorithm. Knowing all 'printable' characters are 8
  8. 'Bytes long, you can shift the bits to the left and still have a printable character.
  9. 'To Decrypt, all you have to do is to shift them left until you have come full circle
  10. 'as in the following calling procedures:
  11. 'to Encrypt: fEncryptString(TheString, nbrPlaces)
  12. 'to Decrypt: fEncryptString(TheString, 8 - nbrPlaces)
  13.  
  14. Dim tmp As Integer, i As Integer, mult As Integer
  15. Dim intLength As Integer, tmpSt As String
  16.  
  17. intLength = Len(TheString)
  18. tmpSt = ""
  19. nbrPlaces = nbrPlaces Mod 8     'no point doing more than 7, besides
  20. mult = 2 ^ nbrPlaces                  'mult (an Integer) would be too small
  21.  
  22. For i = 1 To intLength
  23.   tmp = Asc(Mid$(TheString, i, 1))          'get the ASCII value of each character
  24.   tmp = tmp * mult                             'apply the multiplier
  25.   tmp = tmp Mod 256 + tmp \ 256             'rotate any 'carry' bit
  26.   tmpSt = tmpSt & Chr$(tmp)                 'add the character to the String
  27. Next i
  28.  
  29. fEncryptString = tmpSt
  30. End Function
Jan 24 '07 #4
Thank You so much for all the reply..I will test this 2 codes today and ill let you know what happen..thanx!
Jan 25 '07 #5
NeoPa
32,556 Expert Mod 16PB
You're welcome.
We're interested in success stories as well as problems. It helps other readers of the thread to know that the answer works.
Jan 25 '07 #6
You're welcome.
We're interested in success stories as well as problems. It helps other readers of the thread to know that the answer works.

Hi!I tried your code..Can you please explain to me how it works?
Jan 25 '07 #7
NeoPa
32,556 Expert Mod 16PB
Expand|Select|Wrap|Line Numbers
  1. 'If I told you what this did I'd have to kill you.
  2. Public Function Scramble(strPW As String)
  3.     Dim intIdx As Integer
  4.  
  5.     Scramble = strPW
  6.     For intIdx = 1 To Len(strPW)
  7.         Mid(Scramble, intIdx, 1) = _
  8.             Chr(&H40 Or (Not Asc(Mid(strPW, intIdx, 1))) And &H3F)
  9.     Next intIdx
  10. End Function
Clearly you're not worried about the warning on line one then ;(
It's essentially a Bitwise OR operation.
There is, however, provision made for ensuring that all characters produced are printable characters so, no matter where it us used / stored, you should have no problems.
Jan 25 '07 #8
Expand|Select|Wrap|Line Numbers
  1. 'If I told you what this did I'd have to kill you.
  2. Public Function Scramble(strPW As String)
  3.     Dim intIdx As Integer
  4.  
  5.     Scramble = strPW
  6.     For intIdx = 1 To Len(strPW)
  7.         Mid(Scramble, intIdx, 1) = _
  8.             Chr(&H40 Or (Not Asc(Mid(strPW, intIdx, 1))) And &H3F)
  9.     Next intIdx
  10. End Function
Clearly you're not worried about the warning on line one then ;(
It's essentially a Bitwise OR operation.
There is, however, provision made for ensuring that all characters produced are printable characters so, no matter where it us used / stored, you should have no problems.

Ok. Thanx so much I already got it..Thank you so much!
Jan 26 '07 #9
Hi.

I know that this is a very old thread, but I found it because I wanted to do exactly this - but found that neither solution quite worked for me.

NeoPa's solution works well, but not for punctuation. When you run it on the encrypted string, alpha and numbers return to normal but e.g. space turns to '

ADezii's solution is better, in that sense, but for the right settings will cheerfully return a character less than 32 - for example "P" shifted by 5 gives a LF. Fine if all you are doing is storing it in a field that doesn't care, but in my case I wanted to write it to an external file and that would mess up the record.

So what I came up with in the end was this. Thought I'd share in case anyone else found it useful.

Expand|Select|Wrap|Line Numbers
  1. Function sEncryptString(ByVal sPlainText As String) As String
  2.  
  3.     Dim iIndex As Integer
  4.     Dim iEncoder As Integer
  5.     Dim iEncodedVal As Integer
  6.  
  7.     ' Each character will be XORed with a (different) random value 0-255.
  8.     ' The beauty of XOR is that you undo it simply by XORing with the same value
  9.     '
  10.     ' The output string will be twice as long as the input string,
  11.     ' because we need to store the value that we used to XOR
  12.     '
  13.     ' Because it will be stored in a "plain text" file (e.g. a definition file)
  14.     ' We MUST have printable characters so no XOR value or resultant character code
  15.     ' is permitted to be <32 or 127 (DEL). That is why we are encoding each character
  16.     ' with a different code, because it is easier to check for these values rather than
  17.     ' repeating the entire encode endlessly until we find one that is good.
  18.  
  19.     Randomize                                           ' Initialise the random number generator
  20.     sEncryptString = ""
  21.     For iIndex = 1 To Len(sPlainText)
  22.         Do
  23.             iEncoder = Int(94 * Rnd + 32)               ' Use an encoder value between 32 and 126
  24.             iEncodedVal = Asc(Mid(sPlainText, iIndex, 1)) Xor iEncoder
  25.         Loop While iEncodedVal = 127 Or iEncodedVal < 32
  26.         sEncryptString = sEncryptString & Chr(iEncodedVal) & Chr(iEncoder)
  27.     Next iIndex
  28.  
  29. End Function
  30.  
  31. Function sDecryptString(ByVal sEncryptedString As String) As String
  32.  
  33.     Dim iIndex As Integer
  34.     Dim iDecodedVal As Integer
  35.  
  36.     ' This is the reverse of the encrypt function
  37.     ' Simply take the first of each pair of characters and XOR it with the second
  38.  
  39.     sDecryptString = ""
  40.     For iIndex = 1 To Len(sEncryptedString) Step 2
  41.         iDecodedVal = Asc(Mid(sEncryptedString, iIndex, 1)) Xor Asc(Mid(sEncryptedString, iIndex + 1, 1))
  42.         sDecryptString = sDecryptString & Chr(iDecodedVal)
  43.     Next iIndex
  44.  
  45. End Function
  46.  
Nov 6 '13 #10
NeoPa
32,556 Expert Mod 16PB
There's no reason not to add to an old discussion if it's still relevant and you feel you have something to add. It may be interesting to see an explanation of what the code's doing though.
Nov 7 '13 #11
By all means.

The Encrypt routine goes through the string, one letter at a time, and performs a bitwise Exclusive-Or (XOR) on the ASCII value of the character using a random number that has been generated in the range 32-126. It then adds both the new character and the character representing the random number to the encrypted string.

If you are not familiar with XOR, it is like OR except that two 1s produce a 0 output. It's advantage is that it is completely reversible, so that if C = A XOR B, then A = C XOR B.

My requirement was to write the encrypted string to a plain text file, so I had to have printable characters which didn't include DEL, BKSP or any of the control characters (ASCII values less than 32). So that is why the random number is created in the range it is, and why the XOR function has a loop to ensure that I keep repeating the encoding with different random numbers until I get a printable character.

I could have increased the range of the random number to 255 using a similar loop around the random number generator and setting it to give numbers up to 255, but thought that that was overkill for this application.

The decrypt routine reads the characters from the string in pairs. The first is the encrypted character, and the second is the value that was used to encrypt it. The first is the XORed with the second to recover the original character, which is then added to the output string
Nov 7 '13 #12
NeoPa
32,556 Expert Mod 16PB
Thank you. That was well worth the read :-)

My latest version handles the same problem differently. It uses all 256 possible values, but instead of storing the character itself, which can cause problems in some environments due to many possible values not being printable, it stores (the ASCII codes of) the hex digits of the character. The encryption algorithm used is RC4 (RC4 Encryption Algorithm for VBA and VBScript) and different projects can use different hashes to ensure the data doesn't become too predictable or recognisable.
Nov 7 '13 #13
Interesting, thanks. When I have a little more time, I'll try and get my mind around the RC4 code in the linked article. For the application I am developing, what I have now is probably sufficient, but always good to learn new things.
Nov 7 '13 #14
NeoPa
32,556 Expert Mod 16PB
That is much as my attitude was when I first came across it. Eventually I found the time to incorporte it into my standard code, and I haven't looked back :-)
Nov 7 '13 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marshall Dudley | last post by:
I have an application where I need to encrypt a bit of text, and then I need to be able to decrypt it using a customer's key. I want to make sure that the key to decrypt is NOT on the server...
3
by: CLEAR-RCIC | last post by:
Hello all. I have written a .Net .dll that edits properties in Active Directory. I have to specify an Admin username and password in my LDAP connection string when I bind to the Active Directory....
1
by: jimfortune | last post by:
This idea is still in the process of formulation. I'm considering the idea of storing encrypted data in memo fields. Since the data is for internal use only I don't think the legal limits on...
0
by: Sunny | last post by:
Hi, this is new to me, so I'd like some advise and possible solutions. I'm creating a application, which have to connect to a webservice (also part of the project) and to receive a personalized...
4
by: Andy G | last post by:
If users forget there passwords I want to send a link to them through email so they can click on a link and go to a change password page. eBay does this by sending you a url that looks something...
3
by: Thirsty Traveler | last post by:
I hear that MD5 is not recommended for encrypting database passwords in that it can be compromised. Does anyone have a recomendation (SHA-1, etc.) on an algorithm that would be more appropriate.
19
by: Cord-Heinrich Pahlmann | last post by:
Hi, I have written a tool wich de/encrypts a few of my forum and bloggin-Passwords. My question is how secure it is. The following describes how I have encrypted my passwords. When I log in,...
2
by: Amar | last post by:
Hi All, I want to insert my password into the mysql database by encrypting it so that I can also retrieve the password. Before I was using sha1() for encrypting password,but it is an one way...
2
by: SeeSharp Bint | last post by:
Visual Studio 2005, dotnet, c#. Microsoft SQL Server. Windows XP forms application. Temporarily, for my database application, I have been storing the various elements of database connection...
0
by: xexpertdkx | last post by:
I have a pseudo-code and I want to make it VB executable auto run. Can anyone help? if usb = in usb port then prompt password if password = password then enable copy/paste etc 'decrpyted else...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.