Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void verifyPassword()
- {
- #region readUserInput
- string userInput = "";
- Console.Write("Enter Password:");
- SecureString pwd = new SecureString();
- while (true)
- {
- ConsoleKeyInfo i = Console.ReadKey(true);
- if (i.Key == ConsoleKey.Enter)
- {
- break;
- }
- else if (i.Key == ConsoleKey.Backspace)
- {
- if (pwd.Length > 0)
- {
- pwd.RemoveAt(pwd.Length - 1);
- Console.Write("b b");
- }
- }
- else
- {
- pwd.AppendChar(i.KeyChar);
- Console.Write("*");
- }
- }
- IntPtr bstr = Marshal.SecureStringToBSTR(pwd);
- try
- {
- //Console.WriteLine(Marshal.PtrToStringBSTR(bstr));
- userInput = Marshal.PtrToStringBSTR(bstr);
- }
- finally
- {
- Marshal.FreeBSTR(bstr);
- }
- #endregion
- #region theRealPass
- string password = "123456";
- string pass = "";
- SecureString thePass = new SecureString();
- Array.ForEach(password.ToArray(), thePass.AppendChar);
- thePass.MakeReadOnly();
- password = "";
- IntPtr bstr2 = Marshal.SecureStringToBSTR(thePass);
- //pass = Marshal.PtrToStringBSTR(bstr);
- try
- {
- //Console.WriteLine(Marshal.PtrToStringBSTR(bstr));
- pass = Marshal.PtrToStringBSTR(bstr2);
- }
- finally
- {
- Marshal.FreeBSTR(bstr2);
- }
- #endregion
- bool a = true;
- a = (userInput == pass);
- if (a)
- {
- userInput = "";
- pass = "";
- Console.WriteLine("good");
- }
- else
- {
- Console.WriteLine("nWrong Password,please try again");
- wrongPassword();
- }
- }
- public static void wrongPassword()
- {
- int numbers = 5;
- for (int i = 0; i < numbers; i++)
- {
- verifyPassword();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement