Exemple #1
0
        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);
            }
        }
Exemple #2
0
 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;
     }
 }
Exemple #3
0
 public void UpdateUser(UserInfo user)
 {
     userDal.UpdateUser(user);
 }
Exemple #4
0
 public void UpdateUser(UserInfo user)
 {
     // TODO: need to find out what can you update
     // update password should be a separate operation
 }