jeudi 23 juin 2016
Login Program password masking enhancement in c++
A few days ago, I had asked help from you guys for an advanced(kind of) login system in c++. Thanks to your support, I did get get it right, but now I am looking to add more features to the program. Currently, it is capable of taking in a username string, take in a password char string and also mask the password, and compare them both with pre-set values again and again until they match.
Now , the problem is that since I use getchar() to input data into the char array, even if I press the Enter key, it'll take that as an input for the array. Also, I can only enter values upto 8 characters, after which, even without pressing Enter, it automatically goes to the next step.
I want the code to be modified such that it can take any number of characters as an input, mask them, and then, when the user presses Enter, it stops taking further values to fill up more array characters. So basically, almost like cin except it echoes '*' for every character entered. Sorry for the bad code block editing. Here's my code:
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>`
using namespace std;
int main()
{
int i=0;string u,p;char parr[8],ch;
while (1)
{
system("cls");
cout<<"Enter username."<<endl;
cin>>u;
system("cls");
cout<<"Enter password."<<endl;
for (i=0;i<=7;++i)
{
ch=getch();
parr[i]=ch;
cout<<'*';
}
parr[8]='';
string p="password";
if (u=="username" && parr==p)
{
system("cls");
cout<<"Welcome!";
break;
}
else
{
system("cls");
cout<<"Username and password entered does not match! Please try again.";
}
getch();
}
getch();
}
Inscription à :
Publier les commentaires (Atom)
Aucun commentaire:
Enregistrer un commentaire