Advertisement
Guest User

Untitled

a guest
Aug 25th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. public JsonResult ChangePassword
  2. (string username, string currentPassword, string newPassword)
  3. {
  4. switch (this.membershipService.ValidateLogin(username, currentPassword))
  5. {
  6. case UserValidationResult.BasUsername:
  7. case UserValidationResult.BadPassword:
  8. // abort: return JsonResult with localized error message
  9. // for invalid username/pass combo.
  10. case UserValidationResult.TrialExpired
  11. // abort: return JsonResult with localized error message
  12. // that user cannot login because their trial period has expired
  13. case UserValidationResult.Success:
  14. break;
  15. }
  16.  
  17. // NOW change password now that user is validated
  18. }
  19.  
  20. enum UserValidationResult
  21. {
  22. BadUsername,
  23. BadPassword,
  24. TrialExpired,
  25. Success
  26. }
  27.  
  28. public JsonResult ChangePassword
  29. (string username, string currentPassword, string newPassword)
  30. {
  31. switch (this.membershipService.ValidateLogin(username, currentPassword))
  32. {
  33. case UserValidationResult.BasUsername:
  34. case UserValidationResult.BadPassword:
  35. // abort: return JsonResult with localized error message
  36. // for invalid username/pass combo.
  37. case UserValidationResult.TrialExpired
  38. // abort: return JsonResult with localized error message
  39. // that user cannot login because their trial period has expired
  40. case UserValidationResult.Success:
  41. break;
  42. default:
  43. throw new NotImplementedException
  44. ("Unrecognized UserValidationResult value.");
  45. // or NotSupportedException()
  46. break;
  47. }
  48.  
  49. // Change password now that user is validated
  50. }
  51.  
  52. enum UserValidationResult
  53. {
  54. BadUsername,
  55. BadPassword,
  56. TrialExpired,
  57. ContactUs,
  58. Success
  59. }
  60.  
  61. if( i == 0 ) {
  62.  
  63.  
  64. } else { // i > 0
  65.  
  66.  
  67. }
  68.  
  69. if( i == 0 ) {
  70.  
  71.  
  72. } else if ( i > 0 ) {
  73.  
  74.  
  75. } else {
  76. // i < 0 is now an enforced error
  77. throw new Illegal(...)
  78. }
  79.  
  80. if( i == 0 ) {
  81.  
  82.  
  83. } else { // i != 0
  84. // we can handle both positve or negative, just not zero
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement