and i'v made changes to the code, I'v removed all the junk and the 'username' part....and added coments!!!!!!!
and i'v made changes to the code, I'v removed all the junk and the 'username' part....and added coments!!!!!!!
to add the use of backspace, replace this with the inputcode() function:
- toasterCode://refer to the link from the previous post ... void inputcode(char*&x) { cout<<flush; for(i=0;i<8;i++) { x[i]=char(getch()); cout<<"*"<<flush; if(x[i]==char(13) || x[i]=='\t' || x[i]=='\r' || x[i]==' '){break;} else if(x[i]=='\b'){cout<<"\b";i--;} } fillcode(++i); //fillcode(i+1); } ...
I was wondering if you could please tell me the compiler that this code will work in because it does not want to seem to want to work in mine
Thanks
sp00k
Last edited by sp00k; 05-19-2002 at 01:17 AM.
This is C++, and we're on a C board!Originally posted by Unregistered
to add the use of backspace, replace this with the inputcode() function:
- toasterCode://refer to the link from the previous post ... void inputcode(char*&x) { cout<<flush; for(i=0;i<8;i++) { x[i]=char(getch()); cout<<"*"<<flush; if(x[i]==char(13) || x[i]=='\t' || x[i]=='\r' || x[i]==' '){break;} else if(x[i]=='\b'){cout<<"\b";i--;} } fillcode(++i); //fillcode(i+1); } ...
Now, you could all take note of Prelude's code which does what you want and is easily adapted to store the input for later use, or you could all waste more time talking about it. It's up to you
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
hi you can get this one:
PHP Code:
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "stdlib.h"
#define Back 8
int getcode(void)
{
int t;
t = getch();
if ( ( t == 0 ) || ( t == 0xE0 ) )
t = getch() ;
return t;
}
//---------------------------------------
//---------------------------------------
char *getpass(void)
{
int i, c;
char *pass ;
pass = (char*)malloc(sizeof(char));
i=0;
c=0;
c = getcode();
while( (c != 13) && (i < Back) )
{
if( c == Back )
{
if( i == 0 )
; // Do Nothing....
else
{
i-- ;
printf("\b \b"); //Back than print blank ' ' then back...
}//else
}
else if( ((c>=65) && (c<=90)) || (( c>=97 ) && ( c<=122 )) || (( c>=48 ) && ( c<=57 )))
{ // make sure that the input is not anything but A-Z || a-z || 0-9 ...
pass[i] = c ;
i++ ;
printf("*");
}//else if
c=getcode();
}//while
if( i<8 ) pass[i] = '\0';
// give the string NULL if not full (less than 8) ...
return pass;
}// getpass
//----------------------------------------
//----------------------------------------
int main()
{
char *str1, *str2 = "asd123" ;
str1 = NULL ;
printf("\nHi Please Enter The Pass Word: ");
str1 = getpass();
if( strcmp(str1, str2) == 0 )
printf("\nHi there are EQUAL ...");
else
printf("\nSorry try agen");
return 0 ;
}
- talal*c
>hi you can get this one:
Exactly, why use 9 lines of code when you can write 83. That's much easier for the newbies to understand.
[/sarcasm]
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
Was Prelude's code that complex?
The world is waiting. I must leave you now.
yes.......yes it was
First let me ask you, How was it so complex?
Second, do you still need help?
The world is waiting. I must leave you now.
OK, which part would you like help with?Originally posted by Commander
yes.......yes it was
Now, just to clarify, this code doesn't perform a password comparison. It mearly shows you how to best obtain the password from the user. To expand it to store the password, you'd need to store each ch in an array. You can also cater for backspace by simply removing the last character from the array when a backspace is read. Something like this:Code:/* Prelude's original code */ #include <stdio.h> #include <conio.h> int main(void) { int ch; printf("Enter your password: "); while ((ch = getch()) != '\r') putchar('*'); printf("\nThank you\n"); return 0; }
Alternatively, you could check each letter of the password as you get it from the user (instead of storing it in an array).Code:#include <stdio.h> #include <conio.h> #include <ctype.h> #define PASSLEN 10 int main(void) { int ch, i; char password[PASSLEN+1]; printf("Enter your password: "); i = 0; while ((ch = getch()) != '\r' && i < PASSLEN) { if (ch == '\b') { /* Handle backspace */ if (i > 0) {i--; printf("\b \b");} password[i] = '\0'; } else if (isalnum(ch)) { /* Only characters and numbers considered to be part of the password */ password[i] = ch; putchar('*'); i++; } } password[i] = '\0'; printf("\nThank you, you entered: %s\n", password); return (0); }
Also, doing this kind of thing:
>char master_password[] = "superdupervisor";
is not recommended. You only need to hex dump the exe and someone will find out the password. You should store it as encrypted text.
Last edited by Hammer; 05-20-2002 at 03:32 AM.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]