Lol, it tooks me like 3 hours to make it works, but I finally got it! (sign it as Solved pls)
If anyone is interested, here's the code (it may not be the best one, but at least it works well):
Code:
char * get_psw()
{
string strPass = "";
char c = 0;
int index = 0;
while (c != 13)
{
c = (char)_getch();
if(c == 13)
break;
strPass += c;
if(c != 8)
{
cout << "*";
}
else
cout<<"\b"<<" "<<"\b";
}
char * psw = new char[k_lenght];
unsigned int j = 0, num_bckspc = 0, num_bckspc_done = 0;
bool flag = false;
for(unsigned int cnt = 0; cnt<strPass.length(); cnt++)
{
if(strPass[cnt] == '\b')
{
num_bckspc++;
}
}
while( j<strPass.length())
{
if(strPass[j] == '\b' && j>0)
{
for(unsigned int t = j; t<strPass.length()+1; t++)
strPass[t-1] = strPass[t];
flag = true;
num_bckspc_done++;
}
if(strPass[j] == '\b' && j==0)
{
for(unsigned int t = j; t<strPass.length(); t++)
strPass[t] = strPass[t+1];
flag = true;
}
if(num_bckspc_done == num_bckspc && num_bckspc != 0)
{
unsigned int i = 0;
bool flag1 = false;
while(i<strPass.length())
{
if(strPass[i] == '\b' && j>0)
{
for(unsigned int t = i; t<strPass.length(); t++)
strPass[t] = strPass[t+1];
flag1 = true;
num_bckspc_done++;
}
i++;
if(flag1)
{
i=0;
flag1 = false;
}
}
}
j++;
if(flag)
{
j=0;
flag = false;
}
}
unsigned int f;
for( f=0; f<strPass.length(); f++)
{
psw[f] = strPass[f];
}
psw[f] = '\0';
return psw;
}