0

I'm encrypting the text of a passwordbox in my project using SHA256CryptoServiceProvider but when I want to save the encrypted password into my data base (SQL server 2014 management studio) I encounter this error: Validation failed for one or more entities. I've never encountered such error before so I would be appreciated if you help me. Here is my encryption code:

SHA256CryptoServiceProvider sha2 = new SHA256CryptoServiceProvider();

                Byte[] B1;
                Byte[] B2;

                B1 = UTF8Encoding.UTF8.GetBytes(passwordbox.Password.Trim());
                B2 = sha2.ComputeHash(B1);

                string UserPasswordHashed = BitConverter.ToString(B2);

& here's how I insert it into my SQL table:

wpf1Entities database = new wpf1Entities();
 HashedPasswordTable HP = new HashedPasswordTable();
               
                HP.userpass = UserPasswordHashed.ToString();
                database.HashedPasswordTable.Add(HP);
                database.SaveChanges();
Jackdaw
  • 7,626
  • 5
  • 15
  • 33
  • Please tell us what `wpf1Entities` and `HashedPasswordTable` are, and include a definition for the tables being used in the SQL database – Keith Stein Sep 06 '20 at 19:34
  • Look at this post: [Validation failed for one or more entities. See 'EntityValidationErrors' property for more details](https://stackoverflow.com/questions/7795300/validation-failed-for-one-or-more-entities-see-entityvalidationerrors-propert) – Jackdaw Sep 06 '20 at 19:37

0 Answers0