public void CreateUser(UserInfo userInfo) { if (userInfo == null) { throw new ArgumentNullException(nameof(userInfo)); } if (string.IsNullOrWhiteSpace(userInfo.Username)) { throw new ArgumentNullException(nameof(userInfo.Username)); } if (string.IsNullOrWhiteSpace(userInfo.Password)) { throw new ArgumentNullException(nameof(userInfo.Password)); } if (UsernameExists(userInfo.Username)) { throw new Exception("Username already exists, please enter a different username"); } using (var shazam = new SHA512Managed()) { var salt = GenerateSaltValue(); var passwordAndSalt = userInfo.Password + salt; var hashedPassword = Encoding.UTF8.GetString(shazam.ComputeHash(Encoding.UTF8.GetBytes(passwordAndSalt))); userInfo.Password = hashedPassword; userInfo.Salt = salt; userDal.CreateUser(userInfo); } }
public int CreateUser(UserInfo userInfo) { const string sql = @" insert into Users (Username, Password, Salt, UserType) values (@username, @password, @salt, @userType); select last_insert_rowid() from Users; "; using (var conn = Database.CreateConnection()) { var createdChannelId = conn.Query<int>(sql, new { username = userInfo.Username, password = userInfo.Password, salt = userInfo.Salt, userType = userInfo.UserType }).First(); return createdChannelId; } }
public void UpdateUser(UserInfo user) { userDal.UpdateUser(user); }
public void UpdateUser(UserInfo user) { // TODO: need to find out what can you update // update password should be a separate operation }