コード例 #1
0
        public LoginModel LoginUser(string password)
        {
            LoginModel login = new LoginModel
            {
                UserName     = UserLogin,
                UserPassword = password,
                IsValidated  = false
            };

            if (string.IsNullOrWhiteSpace(login.UserName))
            {
                MessageBox.Show("Missing Login!");
            }

            else if (string.IsNullOrEmpty(login.UserPassword))
            {
                MessageBox.Show("Missing Password!");
            }

            else
            {
                LoginModel user = Queries.GetUser(login.UserName);

                if (user.UserName != null)
                {
                    bool isValidated = HashSalt.VerifyPassword(password, user.Hash, user.Salt);

                    if (isValidated)
                    {
                        login.UserId        = user.UserId;
                        CurrentLogin.UserId = login.UserId;
                        login.IsValidated   = true;
                        MessageBox.Show("Login Sucessfull!");
                    }

                    else
                    {
                        login.IsValidated = false;
                        MessageBox.Show("Wrong Password!");
                    }
                }
            }

            return(login);
        }