Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- FUNCTION THAT GETS A PASSWORD FROM USER
- */
- #include<iostream.h>
- #include<stdio.h>
- #include<conio.h>
- void getpass(char *pass, int l)
- {
- char ch;
- int i=0;
- while(1) //runs until enter is entered
- {
- ch=getch();
- if(ch==13) //checks for enter key
- {
- pass[i]='\0'; //ends with a null ch
- break;
- }
- else if(ch==8) //checks for backspace
- {
- cout<<"\b \b"; //removes asterisk printed
- if(i<l&&i>0)
- i--; //one pos back
- }
- else if(i<(l-1)) //one ch is saved for null ch
- {
- cout<<"*"; //prints asterisk
- pass[i]=ch; //stores in referenced array
- i++;
- }
- }
- }
- void main()
- {
- char username[20], password[20];
- cout<<"ENTER USERNAME: ";
- gets(username);
- cout<<"ENTER PASSWORD: ";
- getpass(password,20); //string passed by reference, with size
- cout<<"\n\nUSERNAME: "<<username;
- cout<<"\nPASSWORD: "<<password;
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement