Пример #1
0
        public void ValidMatch()
        {
            string Salt          = "asdf";
            string PassFromDB    = "pass";
            string IncommingPass = "******";

            var inchashDTO = new HashDTO()
            {
                Original = IncommingPass + Salt
            };

            var dbHashDTO = new HashDTO()
            {
                Original = PassFromDB + Salt
            };

            var incomminghashpass = new HMAC256().Hash(inchashDTO);

            var dbhashpass = new HMAC256().Hash(dbHashDTO);

            var loginDTO = new LoginDTO()
            {
                Password = IncommingPass
            };
            var responseDTO = new ResponseDTO <LoginDTO>()
            {
                Data = new LoginDTO()
                {
                    Salt = Salt
                }
            };

            var validate = new ValidateCredentials()
            {
                loginDTO    = loginDTO,
                responseDTO = responseDTO
            };

            Assert.False((bool)validate.Execute().Result);
        }
Пример #2
0
        /// <summary>
        /// Executes login commands
        /// </summary>
        /// <returns>return username, token, view claims when pass, else fail messages</returns>
        public LoginResponseDTO loginService()
        {
            response          = new LoginResponseDTO();
            response.Messages = new List <string>();

            var userCredential = new UserCredentialTransformer()
            {
                userCredential = this.userCredential
            };

            var incommingloginDTO = (ResponseDTO <LoginDTO>)userCredential.Execute().Result;

            if (incommingloginDTO.IsSuccessful == false)
            {
                response.isSuccessful = false;
                response.Messages.Add("Incorrect Credentials");
                return(response);
            }

            var getUserCredentials = new GetUsersCredentials()
            {
                loginDTO = incommingloginDTO.Data
            };

            var credentials = (ResponseDTO <LoginDTO>)getUserCredentials.Execute().Result;

            if (credentials.IsSuccessful == false)
            {
                response.isSuccessful = false;
                response.Messages.Add("User does not exist");
                return(response);
            }

            var validated = new ValidateCredentials()
            {
                loginDTO    = incommingloginDTO.Data,
                responseDTO = credentials
            };

            var isValidated = (bool)validated.Execute().Result;

            if (isValidated == false)
            {
                response.isSuccessful = false;
                response.Messages.Add("Incorrect Credentials");
                return(response);
            }

            var getToken = new GetLoginToken()
            {
                responseDTO = credentials
            };

            response = (LoginResponseDTO)getToken.Execute().Result;

            if (response.isSuccessful == false)
            {
                response.isSuccessful = false;
                response.Messages.Add("Could not Create Token");
                return(response);
            }

            response.Messages.Add("Success");
            return(response);
        }