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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Recover encrypted field from a database

Recover encrypted field from a database

Scheduled Pinned Locked Moved C#
databasequestioncsharpsql-serversysadmin
3 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.
  • A Offline
    A Offline
    aecordoba
    wrote on last edited by
    #1

    Hi there! I want to save an encrypted password in a database in order to authenticate the users of my application (on C# 2.0). So, I encrypted the password provided by the user, as following: UnicodeEncoding unicodeEncoding = new UnicodeEncoding(); byte[] passwordArray = unicodeEncoding.GetBytes(password); SHA1Managed sha1Managed = new SHA1Managed(); byte[] encryptedPassword = sha1Managed.ComputeHash(passwordArray); Then, I saved the password in 'varbinary(160)' field in a table of database (SQL Server 2005): DataSet.Users.AddUsersRow(userName, encryptedPassword); UsersTableAdapter userTableAdapter = new UsersTableAdapter(); userTableAdapter.Update(DataSet.Users); How can I recover this encrypted password in order to compare it with a new encrypted password provided by the user? This code: byte[] passwordArray = row["Password"]; doesn't compile because "it can't convert object to byte[]". Thank you, in advance.

    -- Adrián Córdoba

    C 1 Reply Last reply
    0
    • A aecordoba

      Hi there! I want to save an encrypted password in a database in order to authenticate the users of my application (on C# 2.0). So, I encrypted the password provided by the user, as following: UnicodeEncoding unicodeEncoding = new UnicodeEncoding(); byte[] passwordArray = unicodeEncoding.GetBytes(password); SHA1Managed sha1Managed = new SHA1Managed(); byte[] encryptedPassword = sha1Managed.ComputeHash(passwordArray); Then, I saved the password in 'varbinary(160)' field in a table of database (SQL Server 2005): DataSet.Users.AddUsersRow(userName, encryptedPassword); UsersTableAdapter userTableAdapter = new UsersTableAdapter(); userTableAdapter.Update(DataSet.Users); How can I recover this encrypted password in order to compare it with a new encrypted password provided by the user? This code: byte[] passwordArray = row["Password"]; doesn't compile because "it can't convert object to byte[]". Thank you, in advance.

      -- Adrián Córdoba

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Try casting it first:

      byte[] passwordArray = (byte[])row["Password"];


      Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

      A 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Try casting it first:

        byte[] passwordArray = (byte[])row["Password"];


        Upcoming events: * Glasgow: Introduction to AJAX (2nd May), SQL Server 2005 - XML and XML Query Plans, Mock Objects, SQL Server Reporting Services... Never write for other people. Write for yourself, because you have a passion for it. -- Marc Clifton My website

        A Offline
        A Offline
        aecordoba
        wrote on last edited by
        #3

        Thank you very, very much!

        -- Adrián Córdoba

        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