public string Authenticate(string username, string password)
        {
            var user = _getUserAuth.Get(username);

            if (user == null)
            {
                throw new NonExistingUserException(_path, "Authenticate()");
            }

            if (!BCrypt.Net.BCrypt.Verify(password, user.Password))
            {
                throw new UserValidationException(_path, "Authenticate");
            }

            return(GenerateKey(user.Username));
        }
Exemplo n.º 2
0
        public void CreateUser(string username, string password)
        {
            var existingUser = _getUserData.Get(username);

            if (existingUser != null)
            {
                throw new ExistingUserException(_path, "Add()");
            }

            var user = new User
            {
                Username  = username,
                Password  = BCrypt.Net.BCrypt.HashPassword(password),
                CreatedAt = DateTime.Now,
            };

            var query =
                $"INSERT INTO user_table (username, password, date_created) " +
                $"VALUES ('{user.Username}', '{user.Password}', '{user.CreatedAt}');";

            _sqlQuery.ExecuteVoid(query);
        }