Ejemplo n.º 1
0
        public AuthenticateResponse Authenticate(AuthenticateRequest model)
        {
            if (string.IsNullOrEmpty(model.Username) || string.IsNullOrEmpty(model.Password))
            {
                return(null);
            }

            var user = _repo.GetUsers().SingleOrDefault(x => x.Username == model.Username);

            // return null if user not found
            if (user == null)
            {
                return(null);
            }

            // check if password is correct
            if (!VerifyPasswordHash(model.Password, user.PasswordHash, user.PasswordSalt))
            {
                return(null);
            }

            // authentication successful so generate jwt token
            var token = generateJwtToken(user);

            return(new AuthenticateResponse(user, token));
        }
Ejemplo n.º 2
0
        public AuthenticateResponse Authenticate(AuthenticateRequest model)
        {
            //Get the user from the repository / database

            var user = _repo.GetUsers().SingleOrDefault(x => x.Username == model.Username && x.Password == model.Password);

            // return null if user not found
            if (user == null)
            {
                return(null);
            }

            //map from DB entity to UserModel for the front-end
            var userModel = Map(user);

            // authentication successful so generate jwt token
            var token = GenerateJwtToken(userModel);

            //return the UserModel to the controller, NOT the entity
            return(new FullStack.ViewModels.AuthenticateResponse(userModel, token));
        }
Ejemplo n.º 3
0
        public AuthenticateResponse Authenticate(AuthenticateRequest model)
        {
            //Get the user from the repository / database

            //*** Note about password. Never save clear text passwords in a database, for this test project it's ok, but change this before you show this project
            //to a potential employer ***

            var user = _repo.GetUsers().SingleOrDefault(x => x.Username == model.Username && x.Password == model.Password);

            // return null if user not found
            if (user == null)
            {
                return(null);
            }

            //map from DB entity to UserModel for the front-end
            var userModel = Map(user);

            // authentication successful so generate jwt token
            var token = GenerateJwtToken(userModel);

            //return the UserModel to the controller, NOT the entity
            return(new AuthenticateResponse(userModel, token));
        }