public void LogInTest()
        {
            User           user  = CreateUser();
            UserLogInDraft draft = new UserLogInDraft()
            {
                Login    = user.Login,
                Password = user.Id.ToString()
            };
            string oldToken = auth.LogIn(draft);
            string newToken = JwtWorker.GenerateTokenString(new Jwt(new Header(),
                                                                    new Payload()
            {
                User = user.Id
            }), user.Password);

            Assert.AreNotEqual(oldToken, newToken);
        }
예제 #2
0
        public string LogIn(UserLogInDraft draft)
        {
            User user = uow.Users.GetByLogin(draft.Login);

            if (user == null)
            {
                throw new InvalidLoginException(invalidLogin);
            }

            string md5Password = Cryptographer.MD5Hash(draft.Password);

            if (!user.Password.Equals(md5Password))
            {
                throw new InvalidPasswordException(invalidPassword);
            }

            return(JwtWorker.GenerateTokenString(new Jwt(new Header(),
                                                         new Payload()
            {
                User = user.Id
            }),
                                                 user.Password));
        }