public static long Create(String login, String password, long roleId) { SHA1Hasher.CalculatePasswordHash(password, out String passwordSalt, out String passwordHash); DAL.tblAuthenticationActor currItem = new DAL.tblAuthenticationActor() { Login = login, PasswordSalt = passwordHash, PasswordHash = passwordHash, IsDeleted = false, RoleId = roleId }; DAL.CurrDBContext.Get().tblAuthenticationActor.Add(currItem); DAL.CurrDBContext.Get().SaveChanges(); long id = currItem.Id; return(id); }
// for password Changing set 'Password' field to value, otherwise set 'Password' field = null // if PasswordSalt and PasswordHash recalculated to new values. It must changed in newActor too public static void Update(Actor newActor) { DAL.tblAuthenticationActor dataItem = DAL.CurrDBContext.Get().tblAuthenticationActor.Where(x => x.Id == newActor.Id).Single(); dataItem.Login = newActor.Login; dataItem.IsDeleted = newActor.IsDeleted; dataItem.RoleId = newActor.RoleId; if (newActor.Password != null) { SHA1Hasher.CalculatePasswordHash(newActor.Password, out String passwordSalt, out String passwordHash); dataItem.PasswordSalt = passwordSalt; dataItem.PasswordHash = passwordHash; newActor.PasswordSalt = passwordSalt; newActor.PasswordHash = passwordHash; } DAL.CurrDBContext.Get().SaveChanges(); }