need help in password?
May 17, 2014 at 8:35am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main(){
string pass ="" ;
char ch;
cout << "Enter pass\n" ;
ch = _getch();
while (ch != 13){//character 13 is enter
if (ch != 8)
{ pass.push_back(ch);
cout << '*' ;
}
ch = _getch();
}
if (pass == "hello" ){
cout << "\nAccess granted :P\n" ;
}else {
cout << "\nAccess aborted...\n" ;
}
getch();
}
the code use in above link is good but one problem i cant able to use backspace to remove mistake if user made any mistake he cant able to remove the mistaken character i need help is this
May 17, 2014 at 8:58am UTC
Modified your code a bit.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;
int main(){
string pass = "" ;
char ch;
cout << "Enter pass: " ;
while ((ch=_getch()) != 13)
{
if (ch == 8) // delete
{
// cant delete from a empty
// string so check this
if (pass.length() > 0) {
pass.erase(pass.length()-1);
cout << "\b \b" ; // backspace and clear
}
}
else
{
// we are appending
pass.push_back(ch);
cout << '*' ;
}
}
if (pass == "hello" ){
cout << "\nAccess granted :P\n" ;
}
else {
cout << "\nAccess aborted...\n" ;
}
_getch();
}
Topic archived. No new replies allowed.