Ejemplo n.º 1
0
        private Task <ClaimsIdentity> GetClaims(AuthenticateUserComand command)
        {
            var customer = _repository.Get(command.UserName);
            var pass     = Encripty.EncryptPassword(command.password).ToString().Substring(0, 12);

            if (customer == null)
            {
                return(Task.FromResult <ClaimsIdentity>(null));
            }

            if (!(customer.UserName == command.UserName && customer.Password == pass))
            {
                return(Task.FromResult <ClaimsIdentity>(null));
            }


            _customer = customer;

            return(Task.FromResult(new ClaimsIdentity(
                                       new GenericIdentity(customer.UserName, "Token"),
                                       new[] {
                new Claim("TES", "User")
            }
                                       )));
        }
Ejemplo n.º 2
0
        public void Get_hash_with_for_email()
        {
            string text = "*****@*****.**";
            string hash = Encripty.Crypt(text, password, key);

            Assert.NotEqual(text, hash);
            Assert.Equal(text, Encripty.Decrypt(hash, password, key));
        }
Ejemplo n.º 3
0
        public void Get_hash_with_alpha_numeric_and_other_letters()
        {
            string text = "5uPms(o0t!7kT~hxgP=xTtj-*6rSvdhI]hV^9tsx1S,*i_0!cn";
            string hash = Encripty.Crypt(text, password, key);

            Assert.NotEqual(text, hash);
            Assert.Equal(text, Encripty.Decrypt(hash, password, key));
        }
Ejemplo n.º 4
0
        public void Get_hash_with_alpha_numeric()
        {
            string text = "5MkqSmxmux6eRVv17nfusWck98lHtc";
            string hash = Encripty.Crypt(text, password, key);


            Assert.NotEqual(text, hash);
            Assert.Equal(text, Encripty.Decrypt(hash, password, key));
        }
Ejemplo n.º 5
0
        public void Get_hash_with_lowercase_compare()
        {
            string text      = "5uPms(o0t!7kT~hxgP=xTtj-*6rSvdhI]hV^9tsx1S,*i_0!cn";
            string textLower = text.ToLower();
            string hash      = Encripty.Crypt(text, password, key);
            string hashLower = Encripty.Crypt(textLower, password, key);

            Assert.NotEqual(text, hash);
            Assert.Equal(text, Encripty.Decrypt(hash, password, key));

            Assert.NotEqual(textLower, hashLower);
            Assert.Equal(textLower, Encripty.Decrypt(hashLower, password, key));

            Assert.NotEqual(textLower, text);
            Assert.NotEqual(hashLower, hash);
        }
        public UserView LoginByEmail(string email, string password)
        {
            UserView userView = null;

            password = Encripty.EncryptString(password);
            User user = _userRepository.LoginByEmail(email, password);

            if (user != null)
            {
                userView = UserToUserView(user);
                Jwt jwt = new Jwt {
                    UserId = user.Id, Token = Guid.NewGuid(), DeadLine = DateTime.Now.AddDays(1)
                };

                Guid insertId = _jwtService.Save(jwt);
                jwt.Id         = insertId;
                userView.Jwt   = jwt;
                userView.Roles = _userRoleService.GetByUserId(user.Id);
            }

            return(userView);
        }
 public Guid Save(User user)
 {
     user.Password = Encripty.EncryptString(user.Password);
     _userRepository.Save(user);
     return(user.Id);
 }