Esempio n. 1
0
        public AuthResponse Auth(AuthRequest request)
        {
            AuthResponse response = new AuthResponse();

            response.Errors  = new List <string>();
            response.Success = true;
            Account account = _accountRepository.GetAccountByEmail(request.Email);

            if (account == null)
            {
                response.Success = false;
                response.Errors.Add("Account does not exist");
                return(response);
            }
            if (SHAHasher.ComputeSha256Hash(account.PasswordHash + request.Password) != account.PasswordHashed)
            {
                response.Success = false;
                response.Errors.Add("Passwords do not match");
            }
            if (!response.Success)
            {
                return(response);
            }

            AuthKey authkey = _authKeyRepository.GenerateAuthKey(request.Email, request.Password);

            response.Success   = true;
            response.AuthKey   = authkey.Key;
            response.AccountId = authkey.AccountId;
            return(response);
        }
Esempio n. 2
0
        public AuthResponse Auth(AuthRequest request)
        {
            AuthResponse response = new AuthResponse();

            response.Errors     = new List <string>();
            response.StatusCode = 200;
            User user = _userRepository.GetUserByEmail(request.Email);

            if (user == null)
            {
                response.StatusCode = 400;
                response.Errors.Add("Account does not exist");
                return(response);
            }
            if (SHAHasher.ComputeSha256Hash(user.PasswordHash + request.Password) != user.PasswordHashed)
            {
                response.StatusCode = 400;
                response.Errors.Add("Passwords do not match");
            }
            if (response.StatusCode != 200)
            {
                return(response);
            }

            AuthKey authkey = _authKeyRepository.GenerateAuthKey(request.Email, request.Password);

            response.StatusCode = 200;
            response.AuthKey    = authkey.Key;
            response.UserId     = authkey.UserId;
            return(response);
        }
Esempio n. 3
0
        public void AddAccount(string email, string password)
        {
            string  hash           = SHAHasher.ComputeSha256Hash(RandomStringGenerator.CreateString(256));
            string  hashedPassword = SHAHasher.ComputeSha256Hash(hash + password);
            Account newAccount     = new Account()
            {
                Email          = email,
                PasswordHash   = hash,
                PasswordHashed = hashedPassword
            };

            _appDbContext.Accounts.Add(newAccount);
            _appDbContext.SaveChanges();
        }
Esempio n. 4
0
        public void AddUser(string email, string username, string password)
        {
            string hash           = SHAHasher.ComputeSha256Hash(RandomStringGenerator.CreateString(256));
            string hashedPassword = SHAHasher.ComputeSha256Hash(hash + password);
            User   newAccount     = new User()
            {
                Email          = email,
                Username       = username,
                PasswordHash   = hash,
                PasswordHashed = hashedPassword
            };

            _appDbContext.Users.Add(newAccount);
            _appDbContext.SaveChanges();
        }
Esempio n. 5
0
        public AuthKey GenerateAuthKey(string email, string password)
        {
            Account account = _accountRepository.GetAccountByEmail(email);

            if (account == null)
            {
                return(null);
            }

            string  hash    = SHAHasher.ComputeSha256Hash(RandomStringGenerator.CreateString(256));
            AuthKey authKey = new AuthKey()
            {
                AccountId = account.AccountId,
                Key       = hash
            };

            _appDbContext.AuthKeys.Add(authKey);
            _appDbContext.SaveChanges();
            return(authKey);
        }
        public AuthKey GenerateAuthKey(string email, string password)
        {
            User user = _userRepository.GetUserByEmail(email);

            if (user == null)
            {
                return(null);
            }

            string  hash    = SHAHasher.ComputeSha256Hash(RandomStringGenerator.CreateString(256));
            AuthKey authKey = new AuthKey()
            {
                UserId = user.Id,
                Key    = hash
            };

            _appDbContext.AuthKeys.Add(authKey);
            _appDbContext.SaveChanges();
            return(authKey);
        }