c# - Create a password encrypted and store it in sqlite to use in authentication -
i have winforms application, login form, , want store username , password encrypted in sqlite database. saw can use salt , hash, don't know how encrypt password in code, , compare when authenticate.
any please?
you need take username , password (the password masked text box, preferably second box confirmation) salt it, , create hash password, , insert plaintext username , salted hash of password in database. can verify users password in future comparing database stored version salted (same salt!) hash of user enters.
note each user should have own salt randomly generate user when create account. (this more secure global salt value hacker discover).
take @ this article. pretty covers bases, don't use sha-1 recommended in article. want slow hash function computationally expensive such bcrypt, or pbkdf2 (which included in .net). see "what makes hash function passwords". (thanks @codeinchaos pointing out).
you can use rfc2898derivebytes in system.security.cryptography create salted hash of password, pbkdf2 style.
byte[] salt = guid.newguid().tobytearray[]; rfc2898derivebytes saltedhash = new rfc2898derivebytes("p@$$w0rd", salt, 1000);
a rule of thumb number of iterations should cause hashing operation take second.
Comments
Post a Comment