Advertisement
EnderAlice

Password Prompt

Apr 14th, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. bool PasswordPrompt(TCHAR *Buffer, size_t Count)
  2. {
  3.     int TypedChar;
  4.     size_t Caret;
  5.  
  6.     ::memset(Buffer, 0, sizeof(TCHAR) * Count);
  7.  
  8.     Caret = 0;
  9.     for(;;)
  10.     {
  11.         TypedChar = ::_gettch();
  12.  
  13.         switch(TypedChar)
  14.         {
  15.         case 3:
  16.             ::memset(Buffer, 0, sizeof(TCHAR) * Count);
  17.             ::_puttch(_T('\n'));
  18.             return false;
  19.  
  20.         case 8: // BACKSPACE
  21.             if(Caret > 0)
  22.             {
  23.                 Buffer[--Caret] = 0;
  24.  
  25.                 ::_puttch(8);
  26.                 ::_puttch(_T(' '));
  27.                 ::_puttch(8);
  28.             }
  29.             break;
  30.  
  31.         case 13: // RETURN
  32.             ::_puttch(_T('\n'));
  33.             return true;
  34.  
  35.         default:
  36.             if(TypedChar >= 32)
  37.             {
  38.                 if((Caret + 1) < Count)
  39.                 {
  40.                     Buffer[Caret++] = TypedChar;
  41.                     ::_puttch(_T('*')); //::_puttch(TypedChar);
  42.                 }
  43.             }
  44.             break;
  45.         }
  46.     }
  47.  
  48.     return false;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement