public SaltHashPair CreateLoginWithPassword(string username, string password) { var crypto = new PBKDF2(); var salt = crypto.GenerateSalt(); var hashedPassword = crypto.Compute(password, salt); return new SaltHashPair(salt, hashedPassword); }
public static Tuple<string, string> HashPassword(string password) { ICryptoService cryptoService = new PBKDF2(); string salt = cryptoService.GenerateSalt(); string hashedPassword = cryptoService.Compute(password, salt); return new Tuple<string, string>(hashedPassword, salt); }
public void Create(User model) { ClearCache(); var crypto = new SimpleCrypto.PBKDF2(); model.PasswordSalt = crypto.GenerateSalt(); model.Password = crypto.Compute(model.Password,model.PasswordSalt); provider.Create(model); }
static void Main(string[] args) { string pass = ""; int id=0; ICryptoService cryptoService = new PBKDF2(); const string pepper = "50.L1`(f761OJdG6fc835M(5(+Ju2!P6,4330_N*/%xz<j7(N15KC'8l997'0c0CEg"; Console.WriteLine("Select user by id:"); if (int.TryParse(Console.ReadLine(),out id)) { using (var context = new AF_Context()) { try { User user = context.Users.First(u => u.UserId == id); if (user != null) { while (string.IsNullOrEmpty(pass)) { Console.WriteLine("Input Password:"); pass = Console.ReadLine(); } user.Salt = cryptoService.GenerateSalt(); user.Password = cryptoService.Compute(cryptoService.Compute(pass, user.Salt), pepper); } context.SaveChanges(); } catch (Exception e) { throw; } } } }
public string ChangePassword(string strpass, string strnewpass, string memberid, string email) { MembersTableAdapters.MembersTableAdapter taMember = new MembersTableAdapters.MembersTableAdapter(); if (taMember.GetDataByMemberID(memberid).Count > 0) { DataRow dtMember = taMember.GetDataByMemberID(memberid).Rows[0]; ValidateLogin valLogin = new ValidateLogin(); if (valLogin.isValid(email, strpass)) { ICryptoService cryptoService = new PBKDF2(); //save this salt to the database string PasswordSalt = cryptoService.GenerateSalt(); //save this hash to the database string hashedPassword = cryptoService.Compute(strnewpass); taMember.UpdatePassword(hashedPassword, PasswordSalt, DateTime.Now, Convert.ToInt32(dtMember["AutoID"])); return "valid"; } else { return "invalid"; } } taMember.Dispose(); return "invalid"; }
protected void btn_newPassword_Click(object sender, EventArgs e) { ICryptoService cryptoService = new PBKDF2(); string password = txtPassword.Text; //save this salt to the database string PasswordSalt = cryptoService.GenerateSalt(); //save this hash to the database string hashedPassword = cryptoService.Compute(password); MembersTableAdapters.MembersTableAdapter taMember = new MembersTableAdapters.MembersTableAdapter(); taMember.UpdatePassword(hashedPassword, PasswordSalt, DateTime.Now, Convert.ToInt32(hfAutoID.Value)); taMember.Dispose(); string strMsg = "<p class=\"header2\">Password Changed</p><p>Now you can login with your new password.</p>"; strMsg += "<p style=\"text-align:right; margin-bottom:1px;\"><input type=button value=\"Log-In Now\" onclick=\"self.location.href='Login.aspx'\"></p><hr>"; litMsgBody.Text = strMsg; }
public ActionResult Login(FormCollection collection) { //SimpleCrypto used to create salts and hashes. ICryptoService cryptoService = new PBKDF2(); Exception e = new Exception(); var member = new MemberModel(); try { member.Member.Add(new Member { UserName = "******" }); string username = collection["username"]; string password = collection["password"]; string salt = cryptoService.GenerateSalt(); ; if (username == "" || password == "") { e.Source = "Du har inte fyllt i fälten för lösenord eller användarnamn."; throw e; } else { string hashedPassword = cryptoService.Compute(password.ToString(), salt); Session["hash"] = member.Member.Find(0).UserName; } if (password != "") { } else { Session["hash"] = ""; } if (username.Contains("kalle")) { return RedirectToAction("Index"); } else { e.Source = "rrr"; throw e; } } catch { TempData["errorData"] = e.Source; return RedirectToAction("Index", "Member"); } }