Aug 24, 2011 at 7:04am UTC
I'm Taking User Name And Password From The User. Does Anyone Know How To Display Only Stars When User Enter The Password?
char pw[];
cout<<"Password: ";
cin>>pw; //Don't Want To Display The PW. Only Start Or Something Like That
Thank you
Last edited on Aug 24, 2011 at 8:26am UTC
Aug 24, 2011 at 7:49am UTC
you have to get the length of the character in the pw array and then use the for loop to print the stars
Aug 24, 2011 at 8:19am UTC
Last edited on Aug 24, 2011 at 8:23am UTC
Aug 24, 2011 at 8:22am UTC
This is not possible using only standard C++. It is the terminal that is doing this which is external to your program. You would have to use a library such as ncurses:
http://en.wikipedia.org/wiki/Ncurses
Last edited on Aug 24, 2011 at 8:22am UTC
Aug 24, 2011 at 11:41am UTC
this is part of my code. But it gives an error. encryption part i can do . I need to fix this error. it tells every time password not matching
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 41 42 43 44 45 46 47 48
#include<iostream>
#include<iomanip>
#include<conio.h>
#include<string>
using namespace std;
void encrypt(char *);
main()
{
char uname[30],pw1[30],pw2[30],c=' ' ;
char *pwPtr;
cout<<"User Name: " ;
cin>>uname;
cout<<"\nPassword: " <<endl;
for (int i=0;c!=13;i++)
{
c=getch();
pw1[i]=c;
cout<<"*" ;
}
c=' ' ;
cout<<"\nReEnter Password: \n" ;
for (int j=0;j<30,c!=13;j++)
{
c=getch();
pw2[j]=c;
cout<<"*" ;
}
if (pw1!=pw2)
{
cout<<"\n\nPasswords Entered Not Matching" <<endl;
}
else
{
pwPtr=pw2;
cout<<"Your Encripterd Password Is: " ;
encrypt(pwPtr);
}
cin.ignore();
cin.get();
}
Last edited on Aug 24, 2011 at 11:52am UTC
Aug 24, 2011 at 11:55am UTC
It'll puzzle you, but you can't compare strings like so! Use strcmp or something similar! What you do just now is comparing some pointer address of string 1 and 2 -> these can't be the same unless string 1 is string 2 even in memory!
Aug 24, 2011 at 11:57am UTC
BTW: the comparison between two pointers is perfectly fine, just not what you want. That's the reason your compiler isn't bitching!
Aug 24, 2011 at 12:04pm UTC
Ah Yeah...Ill try strcmp.Thanks Youuu
Aug 24, 2011 at 12:32pm UTC
yes of course...you print a star before checking whether input is '\n' or not....
So you enter like "bla"<RETURN> what your proggy does is:
b -> print * -> check return -> false go on...
l -> print * ->check return -> false go on...
a -> print * ->check return -> false go on...
return ->print *-> check return -> true stop...