Exemple #1
0
        public User Login(string login, string password, bool onLogin)
        {
            var user = dataBase.Users.FirstOrDefault(u => u.UserName.Equals(login, StringComparison.CurrentCultureIgnoreCase) || u.Email == login);

            if (user == null)
            {
                return(null);
            }

            if (onLogin)
            {
                if (hasher.HashWithSalt(password, hasher.GetSalt(user.Password)) == hasher.GetHashedPasswordWithoutSalt(user.Password))
                {
                    return(user);
                }
            }

            else
            {
                if (password == hasher.GetHashedPasswordWithoutSalt(user.Password))
                {
                    return(user);
                }
            }


            return(null);
        }
Exemple #2
0
        private void OnSuccessfullRegistration(object sender, User user)
        {
            Login(user.Email, hasher.GetHashedPasswordWithoutSalt(user.Password), false);

            if (sender is RegistrationForm registrationForm)
            {
                registrationForm.SuccessfulRegistration -= OnSuccessfullRegistration;
            }
        }