public User Load(ISqlConnectionInfo connection, string username, string password) { SqlQueryParameters parameters = new SqlQueryParameters(); parameters.Where = string.Format("[u].Username = @Username"); parameters.Arguments.Add("Username", username); User user = Load(connection, parameters); if (user == null) { return(null); } int SALT_LENGTH = 8; byte[] salt = new byte[SALT_LENGTH]; for (int i = 0; i < SALT_LENGTH; salt[i] = user.Password[user.Password.Length - SALT_LENGTH + i++]) { ; } byte[] encryptedUnckeckedPassword = PasswordEncryption.Create(password, salt).EncryptedPasswordAndSalt; if (encryptedUnckeckedPassword.SequenceEqual(user.Password)) { return(user); } return(null); }
public ActionResult CreateUser(string name, string status, string type, string password) { MobiChat.Data.User user = new MobiChat.Data.User(); UserStatus userStatus = UserStatus.Active; UserType userType = UserType.CreateManager().Load(int.Parse(type)); Enum.TryParse(status, out userStatus); user.Username = name; user.Guid = Guid.NewGuid(); user.UserStatus = userStatus; user.UserType = userType; user.Password = PasswordEncryption.Create(password).EncryptedPasswordAndSalt; // user.Insert(); return(this.Json(new { status = true })); }