How encrypt and decrypt password ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ripendra007
    New Member
    • Feb 2007
    • 27

    How encrypt and decrypt password ?

    hi,everyone i m creating a login page and i want to encrypt the password before insert that in to database and decrypt it before verification can enybody tell how to do this ?
  • hariharanmca
    Top Contributor
    • Dec 2006
    • 1977

    #2
    Originally posted by Ripendra007
    hi,everyone i m creating a login page and i want to encrypt the password before insert that in to database and decrypt it before verification can enybody tell how to do this ?
    you should be aware of string manipulation and you can use some formula which will convert the actual string and which will getback to actual string..

    Comment

    • Ripendra007
      New Member
      • Feb 2007
      • 27

      #3
      Originally posted by hariharanmca
      you should be aware of string manipulation and you can use some formula which will convert the actual string and which will getback to actual string..


      thanx but i m not satisfied....ok bye the way can u tell me how to write algorithm for it ? or if any site from from where i can download or seen that algorithm...ok plz reply soon

      Comment

      • SteveDouglas
        New Member
        • Feb 2007
        • 3

        #4
        Another alternative which I sometimes use is to encrypt the password into some other form, which you then store in the database, and then you check that the entered password encrypts to the same value for verification purposes.

        This means the encryption doesn't need to be 'reversible' - you never need to get the password back from the stored value, so it's no use to anyone even if they steal the data, and you can encrypt the entered password before sending that for storing or verification, so you never send plain text passwords outside your application.

        If you don't need to be particularly secure, here's a bit of PHP that you could easily convert to C or VB that turns a text password into a lightly-encrypted 'long integer'.

        Store the result of the function as your password in the database. Then when you want to check a password, just hash the entered text and see if the result matches what was stored. That way you never store the actual password, and it is very difficult to turn the stored value back into anything usable.

        Code:
        function hash($key) {
          $h = 0;
        
          for ($n = 0 ; $n < strlen($key) ; $n++) {
            $h = (($h & 0x3FAFCF) * 131) + ord($key{$n});
          }
          return $h;
        }
        Regards,
        Steve

        Comment

        • hariharanmca
          Top Contributor
          • Dec 2006
          • 1977

          #5
          Originally posted by Ripendra007
          thanx but i m not satisfied....ok bye the way can u tell me how to write algorithm for it ? or if any site from from where i can download or seen that algorithm...ok plz reply soon
          http://www.codeproject .com/useritems/Encrypt_an_stri ng.asp

          and there are more search in gogle.

          you should undersatnd the algoritham then use it


          Good luck...

          Comment

          • Ripendra007
            New Member
            • Feb 2007
            • 27

            #6
            Originally posted by SteveDouglas
            Another alternative which I sometimes use is to encrypt the password into some other form, which you then store in the database, and then you check that the entered password encrypts to the same value for verification purposes.

            This means the encryption doesn't need to be 'reversible' - you never need to get the password back from the stored value, so it's no use to anyone even if they steal the data, and you can encrypt the entered password before sending that for storing or verification, so you never send plain text passwords outside your application.

            If you don't need to be particularly secure, here's a bit of PHP that you could easily convert to C or VB that turns a text password into a lightly-encrypted 'long integer'.

            Store the result of the function as your password in the database. Then when you want to check a password, just hash the entered text and see if the result matches what was stored. That way you never store the actual password, and it is very difficult to turn the stored value back into anything usable.

            Code:
            function hash($key) {
              $h = 0;
            
              for ($n = 0 ; $n < strlen($key) ; $n++) {
                $h = (($h & 0x3FAFCF) * 131) + ord($key{$n});
              }
              return $h;
            }
            Regards,
            Steve

            Code:
            Thank you so much will meet with new questions bye ?

            Comment

            • chazcross
              New Member
              • Feb 2007
              • 31

              #7
              .NET has built in functions to do encryption and hashes

              Here is a piece of code i use to create a MD5 Hash

              Code:
              using System;
              using System.Security.Cryptography;
              using System.Text;
              using System.Text.RegularExpressions;
              using System.Web;
              
              public class Security
              {
              	//*********************************************************************
              	//
              	// Security.Encrypt() Method
              	//
              	// The Encrypt method encrypts a clean string into a hashed string
              	//
              	//*********************************************************************
              	public static string Encrypt(string cleanString)
              	{
              		Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
              		Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
              		
              		return BitConverter.ToString(hashedBytes);
              	}
              
              }

              Comment

              Working...