Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. SHA1

SHA1

Scheduled Pinned Locked Moved ASP.NET
questionhelp
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    M Ambigai
    wrote on last edited by
    #1

    Hello sir, I have to encrypt my password.I used the following statement. string pswd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPswd.Text, SHA1 ); Error message is "SHA1 is a type not a variable". How can i do?

    K 1 Reply Last reply
    0
    • M M Ambigai

      Hello sir, I have to encrypt my password.I used the following statement. string pswd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPswd.Text, SHA1 ); Error message is "SHA1 is a type not a variable". How can i do?

      K Offline
      K Offline
      Kelly Herald
      wrote on last edited by
      #2

      The second parameter is expecting a string not an enum. Try this:

      string pswd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPswd.Text, **"SHA1"** );

      Kelly Herald Software Developer

      M 1 Reply Last reply
      0
      • K Kelly Herald

        The second parameter is expecting a string not an enum. Try this:

        string pswd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPswd.Text, **"SHA1"** );

        Kelly Herald Software Developer

        M Offline
        M Offline
        M Ambigai
        wrote on last edited by
        #3

        Sir, How can i decode it again to login?

        K 1 Reply Last reply
        0
        • M M Ambigai

          Sir, How can i decode it again to login?

          K Offline
          K Offline
          Kelly Herald
          wrote on last edited by
          #4

          A hash is one way. It cannot be decrypted. However, you can just compare the newly generated hash with the one stored like below.

          string storedpswd = ... // retrieve stored password from your storage location
          string newpswd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPswd.Text, "SHA1" );
          if (newpswd == storedpswd)
          {
          // passwords match
          }else
          {
          // passwords do not match
          }

          Kelly Herald Software Developer

          M 1 Reply Last reply
          0
          • K Kelly Herald

            A hash is one way. It cannot be decrypted. However, you can just compare the newly generated hash with the one stored like below.

            string storedpswd = ... // retrieve stored password from your storage location
            string newpswd = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPswd.Text, "SHA1" );
            if (newpswd == storedpswd)
            {
            // passwords match
            }else
            {
            // passwords do not match
            }

            Kelly Herald Software Developer

            M Offline
            M Offline
            M Ambigai
            wrote on last edited by
            #5

            Sir, To encrypt and also decrypt what algorithm can be used

            K 1 Reply Last reply
            0
            • M M Ambigai

              Sir, To encrypt and also decrypt what algorithm can be used

              K Offline
              K Offline
              Kelly Herald
              wrote on last edited by
              #6

              You can use TripleDES, Rijndael, or any of the non-hashing algorithms located in the System.Security.Cryptography namespace. Below is a link to MSDN's library for the TripleDES class and it has a complete example of how to encrypt and decrypt data. The other algorithms can also be found in the MSDN library. TripleDESCryptoServiceProvider Class[^]

              Kelly Herald Software Developer

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups