Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace UserLogin
- {
- class LoginValidation
- {
- private string username;
- private string password;
- private string errorMessage;
- public LoginValidation(string username, string password)
- {
- this.username = username;
- this.password = password;
- }
- public static UserRoles currentUserRole
- {
- get;
- private set;
- }
- public string ErrorMessage { get; private set; }
- public bool ValidateUserInput(User user)
- {
- bool emptyUsername;
- emptyUsername = username.Equals(String.Empty);
- if (emptyUsername)
- {
- ErrorMessage = "No username given!";
- return false;
- }
- bool emptyPassword;
- emptyPassword = password.Equals(String.Empty);
- if (emptyPassword)
- {
- ErrorMessage = "No password given!";
- return false;
- }
- if (username.Length < 5)
- {
- ErrorMessage = "Username must be at least 5 symbols long!";
- return false;
- }
- if (password.Length < 5)
- {
- ErrorMessage = "Password too short!";
- return false;
- }
- User match = UserData.IsUserPassCorrect(username, password);
- if (match != null)
- {
- user.username = match.username;
- user.password = match.password;
- user.facNum = match.facNum;
- user.role = match.role;
- currentUserRole = (UserRoles)match.role;
- }
- else
- {
- ErrorMessage = "Username or password is incorrect!";
- return false;
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement