Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. /*
  2. FUNCTION THAT GETS A PASSWORD FROM USER
  3. */
  4.  
  5. #include<iostream.h>
  6. #include<stdio.h>
  7. #include<conio.h>
  8.  
  9. void getpass(char *pass, int l)
  10. {
  11. char ch;
  12. int i=0;
  13. while(1) //runs until enter is entered
  14. {
  15. ch=getch();
  16. if(ch==13) //checks for enter key
  17. {
  18. pass[i]='\0'; //ends with a null ch
  19. break;
  20. }
  21. else if(ch==8) //checks for backspace
  22. {
  23. cout<<"\b \b"; //removes asterisk printed
  24. if(i<l&&i>0)
  25. i--; //one pos back
  26. }
  27. else if(i<(l-1)) //one ch is saved for null ch
  28. {
  29. cout<<"*"; //prints asterisk
  30. pass[i]=ch; //stores in referenced array
  31. i++;
  32. }
  33. }
  34. }
  35. void main()
  36. {
  37. char username[20], password[20];
  38. cout<<"ENTER USERNAME: ";
  39. gets(username);
  40. cout<<"ENTER PASSWORD: ";
  41. getpass(password,20); //string passed by reference, with size
  42. cout<<"\n\nUSERNAME: "<<username;
  43. cout<<"\nPASSWORD: "<<password;
  44. getch();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement