Advertisement
userxbw

Password mask c++

Aug 13th, 2022
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.30 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. /* compile using -std=c++17 */
  7. using
  8. std::cin,
  9. std::cout,
  10. std::endl,
  11. std::string;
  12.  
  13. /* get input stright off cli
  14. on keypress
  15.  
  16. https://replit.com/talk/learn/Detecting-keypresses-in-c-without-pressing-enter/28460
  17.  
  18.  
  19. */
  20. int keypress() {
  21.   system ("/bin/stty raw");
  22.   int c;
  23.   c = getc(stdin);
  24.   system ("/bin/stty cooked");
  25.   return c;
  26. }
  27.  
  28.  
  29.  
  30. int main(){
  31.  
  32. string ast;
  33. int d=0,key;
  34.  
  35.  do {
  36.      key = keypress();
  37. /* 13 is the ascii number
  38.    for return key */
  39.        if(key == 13)
  40.            break;
  41. #ifdef __linux__
  42.    system("clear");
  43. #elif __WIN32
  44.   system("cls");
  45. #endif
  46.  
  47.    cout << key << " ";
  48.   /* keep adding * to string
  49.     then update cli */
  50.     ast +="*";
  51.  
  52. #ifdef __linux__
  53.    system("clear");
  54. #elif __WIN32
  55.   system("cls");
  56. #endif
  57.  
  58. std::cout << ast;
  59.   d++;
  60.   } while (1);
  61.  
  62. char c;
  63. string password,
  64. pwcheck="mypasswd";
  65.  
  66. cout<<"enter password\n";
  67.  
  68. /* loop condition: get a character,
  69. while it isn't a newline
  70. (end of password), */
  71.  
  72. while ((c=getchar()) != '\n')
  73. {
  74. // put it onto the back of the password
  75.     password.push_back(c);
  76. // output a '*' character
  77.     putchar('*');
  78. }
  79.  
  80. if(password != pwcheck)
  81. cout<<"your password no good\n";
  82. else
  83. cout<<"password matched\n";
  84.  
  85.  
  86. return 0;
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement