Example #1
0
        public Session Login(Credentials credentials, string userIP)
        {
            var citizen = citizensRepository.FirstOrDefault(u => u.Entity.Name == credentials.Username);

            if (citizen != null && citizen.Password == credentials.PasswordHash)
            {
                CreateSessionParameters parameters = new CreateSessionParameters()
                {
                    IP         = userIP,
                    RememberMe = credentials.RememberMe,
                    CitizenID  = citizen.ID
                };
                var session = CreateSession(parameters);
                return(session);
            }
            return(null);
        }
        public override void Validate(LoginViewModel model, ValidatorAction action = ValidatorAction.Login)
        {
            var citizen = citizenRepository.FirstOrDefault(c => c.Entity.Name == model.Name);

            if (citizen == null)
            {
                AddError("Citizen does not exist!", () => model.Name);
            }
            else
            {
                var hash = SHA256.Encode(model.Password);
                if (hash != citizen.Password)
                {
                    AddError("Password does not match!", () => model.Password);
                }
            }
        }