/// <summary> /// Ă„ndert das Passwort eines Users /// </summary> /// <param name="name">User Name</param> /// <param name="password">Aktuelles User Password</param> /// <param name="newPassword">Neues User Password</param> /// <returns>Einen HttpStatusCode OK bei Erfolg InternalServerError bei Fehlschlag</returns> public HttpStatusCode ChangePassword(string name, string password, string newPassword) { //Validierung des Users var User = Login(name, password); if (User != null) { var con = DbHelper.GetDbConnection(); con.Open(); //Erstellt einen neuen Hash und Updated diesen und den Salt des Users var HashnSalt = SaltHashHelper.CreateHash(newPassword); UserAccess.ChangeHash(con, name, HashnSalt.Item1); UserAccess.ChangeSalt(con, name, HashnSalt.Item2); con.Close(); return(HttpStatusCode.OK); } else { return(HttpStatusCode.BadRequest); } }
public void ChangePassword() { var con = DbHelper.GetDbConnection(); con.Open(); var name = "Justin_Vazquez"; var password = "******"; var newPassword = "******"; if (!string.IsNullOrWhiteSpace(UserAccess.GetName(con, name))) { var userID = UserAccess.GetIdByName(con, name); var hash = UserAccess.GetHash(con, userID); var salt = UserAccess.GetSalt(con, userID); try { if (SaltHashHelper.ValidatePassword(password, hash, salt)) { var HashnSalt = SaltHashHelper.CreateHash(newPassword); UserAccess.ChangeHash(con, name, HashnSalt.Item1); UserAccess.ChangeSalt(con, name, HashnSalt.Item2); con.Close(); } else { Console.Write("Error"); } } catch (Exception error) { Console.Write(error); } finally { con.Close(); } } }