Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace UserLogin
  4. {
  5. class LoginValidation
  6. {
  7. private string username;
  8. private string password;
  9. public string errorException
  10. {
  11. get; private set;
  12. }
  13.  
  14. public static UserRoles currentUserRole
  15. {
  16. get; private set;
  17. }
  18.  
  19. public static string currentUserUsername
  20. {
  21. get; private set;
  22. }
  23.  
  24. // Delegate example
  25. public delegate void ActionOnError(string errorMsg);
  26.  
  27. private ActionOnError error;
  28.  
  29. public LoginValidation(string username, string password, ActionOnError error)
  30. {
  31. this.username = username;
  32. this.password = password;
  33. this.error = error;
  34. }
  35.  
  36. public bool ValidateUserInput(ref User user)
  37. {
  38. currentUserRole = (UserRoles)user.roleId;
  39.  
  40. bool isEmptyUsername = this.username.Equals(String.Empty);
  41. if (isEmptyUsername || this.username.Length < 5)
  42. {
  43. this.error("The username must be at least 5 symbols long");
  44. currentUserRole = UserRoles.ANONYMOUS;
  45. return false;
  46. }
  47.  
  48. bool isEmptyPassword = this.password.Equals(String.Empty);
  49. if (isEmptyPassword || this.password.Length < 5)
  50. {
  51. this.error( "The password must be at least 5 symbols long");
  52. currentUserRole = UserRoles.ANONYMOUS;
  53. return false;
  54. }
  55.  
  56. user = UserData.IsUserPassCorrect(user);
  57.  
  58. if (user == null)
  59. {
  60. this.error("The username and the password are different");
  61. currentUserRole = UserRoles.ANONYMOUS;
  62. return false;
  63. }
  64.  
  65. currentUserRole = (UserRoles)user.roleId;
  66. LoginValidation.currentUserUsername = user.username;
  67.  
  68. // Set activity in the Logger
  69. Logger.LogActivity((Activities)0, "logged");
  70.  
  71. return true;
  72. }
  73. }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement