Advertisement
Guest User

Untitled

a guest
Feb 9th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. string setPass(bool show_asterisk = true)
  2. {
  3. const char BACKSPACE = 8;//ASCII code for BACKSPACE Key
  4. const char ENTER = 13;//ASCII code for ENTER Key
  5. string pass = " ";//initialize string
  6. char c = ' ';//initialize character
  7.  
  8. while ((c = _getch()) != ENTER)
  9. {
  10. if (c == BACKSPACE)
  11. {
  12. if (pass.length() != 0)
  13. {
  14. if (show_asterisk)
  15. cout << "b b";
  16. pass.resize(pass.length() - 1); //resize the length of pass
  17. }
  18. }
  19. else if (c == 0 || c == 224)//when player press esc key
  20. {
  21. _getch();
  22. continue;
  23. }
  24. else
  25. {
  26. pass.push_back(c);
  27. cout << '*';
  28. }
  29. }
  30. cout << endl;
  31. return pass;
  32. }
  33.  
  34. cout << "==================" << endl;
  35. cout << " login " << endl;
  36. cout << " ID:";
  37. cin >> id;
  38. cout << " Password:";
  39. cin >> pwd;
  40. pwd = setPass();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement