public static byte[] HashPassword(SystemAdmin admin, string password) { using (var service = new SystemAdminService()) { var salt = CreateSalt(32); admin.PasswordSalt = salt; admin.PasswordHash = GenerateSaltedHash(Encoding.ASCII.GetBytes(password), admin.PasswordSalt); service.Update(admin); return(admin.PasswordHash); } }
public static bool ResetSystemAdminPassword(string token, SystemAdmin admin, byte[] newPasswordHash) { using (var service = new SystemAdminTokenService()) { var adminToken = service.GetWhere(SystemAdminTokenService.TokenCol == token).FirstOrDefault(); if (adminToken != null && admin != null && adminToken.Expires > DateTime.Now.ToUniversalTime() && adminToken.SystemAdmin.Code == admin.Code) { service.Delete(adminToken.Code); using (var adminService = new SystemAdminService()) { admin.PasswordHash = newPasswordHash; adminService.Update(admin); } return(true); } return(false); } }
public ActionResult EditAdmin(int Code, string FirstName, string LastName, string Email, string Phone) { Phone = Regex.Replace(Phone, @"[^A-Za-z0-9]+", ""); if (Phone.Length == 10) { Phone = "1" + Phone; } using (var service = new SystemAdminService()) { SystemAdmin p = service.Get(Code); p.FirstName = FirstName; p.LastName = LastName; p.Email = Email; p.Phone = Phone; service.Update(p); } return(RedirectToAction("Admins", new RouteValueDictionary( new { controller = "SystemAdmin", action = "Admins" }))); }