.net - Password hashing in a C# Windows app, absent ASP.NET's FormsAuthentication? -
my win form app doesn't seem formsauthentication, i'm totally new hashing convert welcome. thanks.
//write hash protected textbox tbpassword; protected literal lihashedpassword; { string strhashedpassword = formsauthentication.hashpasswordforstoringinconfigfile(tbpassword.text, "sha1"); lihashedpassword.text = "hashed password is: " + strhashedpassword; } //read hash string struserinputtedhashedpassword = formsauthentication.hashpasswordforstoringinconfigfile( tbpassword.text, "sha1"); if(struserinputtedhashedpassword == getusershashedpasswordusingusername(tbusername.text)) { // sign-in successful } else { // sign-in failed }
using system.security.cryptography; public static string encodepasswordtobase64(string password) { byte[] bytes = encoding.unicode.getbytes(password); byte[] inarray = hashalgorithm.create("sha1").computehash(bytes); return convert.tobase64string(inarray); }
Comments
Post a Comment