Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. public static void verifyPassword()
  2. {
  3. #region readUserInput
  4. string userInput = "";
  5. Console.Write("Enter Password:");
  6.  
  7. SecureString pwd = new SecureString();
  8. while (true)
  9. {
  10. ConsoleKeyInfo i = Console.ReadKey(true);
  11. if (i.Key == ConsoleKey.Enter)
  12. {
  13. break;
  14. }
  15. else if (i.Key == ConsoleKey.Backspace)
  16. {
  17. if (pwd.Length > 0)
  18. {
  19. pwd.RemoveAt(pwd.Length - 1);
  20. Console.Write("b b");
  21. }
  22. }
  23. else
  24. {
  25. pwd.AppendChar(i.KeyChar);
  26. Console.Write("*");
  27. }
  28. }
  29. IntPtr bstr = Marshal.SecureStringToBSTR(pwd);
  30. try
  31. {
  32. //Console.WriteLine(Marshal.PtrToStringBSTR(bstr));
  33. userInput = Marshal.PtrToStringBSTR(bstr);
  34. }
  35. finally
  36. {
  37. Marshal.FreeBSTR(bstr);
  38. }
  39. #endregion
  40.  
  41. #region theRealPass
  42. string password = "123456";
  43. string pass = "";
  44. SecureString thePass = new SecureString();
  45. Array.ForEach(password.ToArray(), thePass.AppendChar);
  46. thePass.MakeReadOnly();
  47. password = "";
  48. IntPtr bstr2 = Marshal.SecureStringToBSTR(thePass);
  49. //pass = Marshal.PtrToStringBSTR(bstr);
  50. try
  51. {
  52. //Console.WriteLine(Marshal.PtrToStringBSTR(bstr));
  53. pass = Marshal.PtrToStringBSTR(bstr2);
  54. }
  55. finally
  56. {
  57. Marshal.FreeBSTR(bstr2);
  58. }
  59. #endregion
  60. bool a = true;
  61. a = (userInput == pass);
  62.  
  63. if (a)
  64. {
  65. userInput = "";
  66. pass = "";
  67. Console.WriteLine("good");
  68. }
  69. else
  70. {
  71. Console.WriteLine("nWrong Password,please try again");
  72. wrongPassword();
  73. }
  74.  
  75. }
  76. public static void wrongPassword()
  77. {
  78. int numbers = 5;
  79. for (int i = 0; i < numbers; i++)
  80. {
  81. verifyPassword();
  82. }
  83.  
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement