Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace UserLogin
  8. {
  9.     class LoginValidation
  10.     {
  11.         private string username;
  12.         private string password;
  13.         private string errorMessage;
  14.  
  15.         public LoginValidation(string username, string password)
  16.         {
  17.             this.username = username;
  18.             this.password = password;
  19.         }
  20.  
  21.         public static UserRoles currentUserRole
  22.         {
  23.             get;
  24.  
  25.             private set;
  26.         }
  27.  
  28.         public string ErrorMessage { get; private set; }
  29.  
  30.         public bool ValidateUserInput(User user)
  31.         {
  32.        
  33.             bool emptyUsername;
  34.             emptyUsername = username.Equals(String.Empty);
  35.             if (emptyUsername)
  36.             {
  37.                 ErrorMessage = "No username given!";
  38.                 return false;
  39.             }
  40.  
  41.             bool emptyPassword;
  42.             emptyPassword = password.Equals(String.Empty);
  43.             if (emptyPassword)
  44.             {
  45.                 ErrorMessage = "No password given!";
  46.                 return false;
  47.             }
  48.  
  49.             if (username.Length < 5)
  50.             {
  51.                 ErrorMessage = "Username must be at least 5 symbols long!";
  52.                 return false;
  53.             }
  54.  
  55.             if (password.Length < 5)
  56.             {
  57.                 ErrorMessage = "Password too short!";
  58.                 return false;
  59.             }
  60.  
  61.             User match = UserData.IsUserPassCorrect(username, password);
  62.  
  63.             if (match != null)
  64.             {
  65.                 user.username = match.username;
  66.                 user.password = match.password;
  67.                 user.facNum = match.facNum;
  68.                 user.role = match.role;
  69.  
  70.                 currentUserRole = (UserRoles)match.role;
  71.             }
  72.             else
  73.             {
  74.                 ErrorMessage = "Username or password is incorrect!";
  75.                 return false;
  76.             }
  77.  
  78.             return true;
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement