| | |
Little help with creating a C++ password function
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2008
Posts: 23
Reputation:
Solved Threads: 0
Firs of all hello guys.And then straight to the point
Ok so my trouble is with creating a password function that will display '*' instead of normal chars.So here is my code:
The first problem I came onto was that the program didn't handel backspaces and displayed them as '*' as well ,but i fixed that. Now the program displayes the backspaces right but it adds the to the string Pass and then adds the next letter I type resulting wrong password.
if I type "zerr" then "\b" and then "ozone" it results in "zerr\bozone". Please help .Any assistance will be appreciated.
Ok so my trouble is with creating a password function that will display '*' instead of normal chars.So here is my code: C++ Syntax (Toggle Plain Text)
string EnterPass() { string Pass=""; char ch=getch(); while (ch != '\r') { if(ch=='\b') cout<<'\b'<<' '<<'\b'; else { cout << '*'; Pass += ch; } ch=getch(); } return Pass; } bool Access() { string password=EnterPass(); if(password=="zerozone") return true; else return false; }
if I type "zerr" then "\b" and then "ozone" it results in "zerr\bozone". Please help .Any assistance will be appreciated.
•
•
Join Date: Jan 2008
Posts: 3,831
Reputation:
Solved Threads: 501
How about changing this:
to this:
You'd have to add code to make sure that you can't backspace on the empty string but it works otherwise as far as I have tested it.
C++ Syntax (Toggle Plain Text)
if (ch=='\b') cout<<'\b'<<' '<<'\b';
to this:
C++ Syntax (Toggle Plain Text)
if (ch=='\b') { cout<<'\b'<<' '<<'\b'; Pass.resize (Pass.length () - 1); }
You'd have to add code to make sure that you can't backspace on the empty string but it works otherwise as far as I have tested it.
![]() |
Similar Threads
- Apache (Linux Servers and Apache)
- Authenticate Username and Password (ASP.NET)
- Open In New Window Php (PHP)
- Creating login screens in VB6 (Visual Basic 4 / 5 / 6)
- Creating a Login Page (ASP)
- Creating a login page in PHP (PHP)
- Problem in displaying returned value from function (C#)
- Script stores data in wrong MySQL columns (MySQL)
- Using passwd in a perl file to automate user creation (Perl)
- Error Creating Folder message during installation (OS X)
Other Threads in the C++ Forum
- Previous Thread: Need help with loop
- Next Thread: plzz solve my problem
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






