Jump to content

Password prgram released!!!


Recommended Posts

Here's the Password program by me in C A big thanks to Anindya1989 Its still in beta version And needs improvemnts!!

#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<dos.h>

void main()

{

char input[20],display[20];

int a,l,b;

clrscr();

printf("entert length of password max 20"); /*password length for creating array */

scanf("%d",&l);

printf("\nplease Enter the password you want in letters a-z And no. 0-9 :");

/* loop for storing each character in the array */

for(a=0;a<l;a++)

{

input[a]=getch();

printf("*");

}

input[a]='\0';

/*human testor say  not a bot test */

A:

printf("\n\ntype 123 to proceed:"); /*User asked to type 123*/

scanf("%d",&B);

if(b==123) /*If b is equal 123 than proceed or execute else part*/

{

printf("\nwait few seconds while we proceed :");    /*Making user fool that we endeed processing*/

for(a=0;a<=5;a++)

{

    printf(".");

    delay(200);

}

printf("\nCorrect Answer\n");

}

else

{

    printf("\nwait few seconds while we proceed :");

    for(a=0;a<=5;a++)

    {

printf(".");

delay(200);

    }

    printf("\nTry again");

    goto A;

}

B:

printf("\n\nType \"show\" for displaying password you have just entered :"); /*User requested to Enter show to display password entered*/

scanf("%s",display);

if(strcmp(display,"show")==0)

{

    printf("wait while we proceed"); /*Making it more realistic */

    for(a=0;a<=5;a++)

{

    printf(".");

    delay(200);

}

printf("\nCorrect Answer");

}

else

{

    printf("\nwait few seconds while we proceed :");

    for(a=0;a<=5;a++)

    {

printf(".");

delay(200);

    }

    printf("\nTry again");

    goto B;

}

printf("Your password:%s",input); /*Dispay store info(password) in input[pass]*/

getch();

}

Link to comment
Share on other sites

the problem i'm facing now is it takes backspace too as a password so what to do for it? And whats the ASCII value of backspace?Do i need to insert ASCII value of each key i need for specific functions?or already a pre made function exist?

you can use an if condition to check every input. and if '\0' comes along, subtract 2 from i. it will overwrite the existing characters
Link to comment
Share on other sites

you can use an if condition to check every input. and if '\0' comes along, subtract 2 from i. it will overwrite the existing characters

dude for backspace i think i need the ASCII value of backspace because than hw it will differentiate b/w back space and other characters?
Link to comment
Share on other sites

Here's the Password program by me in C A big thanks to Anindya1989 Its still in beta version And needs improvemnts!!

CrackUC this is a very nice attempt at making this program but you can improve this program by making it more efficient and by not using GOTO :P. For example you have used --

 printf("wait while we proceed"); /*Making it more realistic */
    for(a=0;a<=5;a++)
   {
       printf(".");
       delay(200);
   }

You have used the above mentioned portion of code both in the if and also in the else part, but why? If the portion of code is common in both if and else part then you should write that part outside the if-else condition. That way you dont have to rewrite the same code twice.

You have also mentioned that your program accepts backspace as a character but thats not the only problem. You haven't used any filter so your program will accept all types of non printable characters. So you need to protect your program against that.

I'm rewriting your program a bit and including the backspace feature to erase the last entered character. See if this works--

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>


char* getPassword();
bool checkHuman();
void displayPassword(char*);


char* getPassword()
{
        char pass[21]= "";
	char ch;
	printf("Enter password(20 characters max): ");
	ch=getch();
	while((ch != '\r') && (ch != '\n'))
	{
		if((ch==127)||(ch<=31))
		{
			if(strlen(pass)>0)
			{
				printf("\b \b");
				pass[strlen(pass) -1] = '\0';
			}
		}
		else
		{
                        int len = strlen(pass);
                        if(len<20)
                        {
                            pass[len] =ch;
                            pass[len + 1] = '\0';
      			    printf("*");
                        }
		}
      			ch = getch();
		
   	}
        return pass;
}

bool checkHuman()
{
       int a,b;     
       printf("\n\ntype 123 to proceed:"); /*User asked to type 123*/
       scanf("%d",&;

       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }

      if(b==123) /*If b is equal 123 than proceed or execute else part*/
      {       
             printf("\nCorrect Answer\n");
             return true;
       }
      else
      {
             printf("\nTry Again\n");
             return false;
       }
}

void displayPassword(char *pass)
{
       printf("\n\nType \"show\" for displaying password you have just entered :"); /*User requested to Enter show to display password entered*/
       scanf("%s",display);
       
       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }
      
      if((strcmp(display,"show")==0) 
      {       
             printf("\nCorrect Answer\n");
             printf("Your password:%s",pass); /*Dispay store info(password) in input[pass]*/
       }
      else
      {
             printf("\nTry Again\n");
             displayPassword(Pass);
       }
}


int main()
{
       system("cls");
       char *password;
       password= new char[21];
       while(true)
       {
                strcpy(password,getPassword());
                if(checkHuman())
               {
                      displayPassword(password);
                      break;
               }
               else
                     continue;
      }
      system("pause");
}

I haven't compiled it to check for errors. You please do it and tell me if there are any errors. Compile the code just as i have written dont add your own main function like last time :P.

Link to comment
Share on other sites

CrackUC this is a very nice attempt at making this program but you can improve this program by making it more efficient and by not using GOTO :P. For example you have used --

 printf("wait while we proceed"); /*Making it more realistic */
    for(a=0;a<=5;a++)
   {
       printf(".");
       delay(200);
   }

You have used the above mentioned portion of code both in the if and also in the else part, but why? If the portion of code is common in both if and else part then you should write that part outside the if-else condition. That way you dont have to rewrite the same code twice.

You have also mentioned that your program accepts backspace as a character but thats not the only problem. You haven't used any filter so your program will accept all types of non printable characters. So you need to protect your program against that.

I'm rewriting your program a bit and including the backspace feature to erase the last entered character. See if this works--

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>


char* getPassword();
bool checkHuman();
void displayPassword(char*);


char* getPassword()
{
        char pass[21]= "";
	char ch;
	printf("Enter password(20 characters max): ");
	ch=getch();
	while((ch != '\r') && (ch != '\n'))
	{
		if((ch==127)||(ch<=31))
		{
			if(strlen(pass)>0)
			{
				printf("\b \b");
				pass[strlen(pass) -1] = '\0';
			}
		}
		else
		{
                        int len = strlen(pass);
                        if(len<20)
                        {
                            pass[len] =ch;
                            pass[len + 1] = '\0';
      			    printf("*");
                        }
		}
      			ch = getch();
		
   	}
        return pass;
}

bool checkHuman()
{
       int a,b;     
       printf("\n\ntype 123 to proceed:"); /*User asked to type 123*/
       scanf("%d",&;

       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }

      if(b==123) /*If b is equal 123 than proceed or execute else part*/
      {       
             printf("\nCorrect Answer\n");
             return true;
       }
      else
      {
             printf("\nTry Again\n");
             return false;
       }
}

void displayPassword(char *pass)
{
       printf("\n\nType \"show\" for displaying password you have just entered :"); /*User requested to Enter show to display password entered*/
       scanf("%s",display);
       
       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }
      
      if((strcmp(display,"show")==0) 
      {       
             printf("\nCorrect Answer\n");
             printf("Your password:%s",pass); /*Dispay store info(password) in input[pass]*/
       }
      else
      {
             printf("\nTry Again\n");
             displayPassword(Pass);
       }
}


int main()
{
       system("cls");
       char *password;
       password= new char[21];
       while(true)
       {
                strcpy(password,getPassword());
                if(checkHuman())
               {
                      displayPassword(password);
                      break;
               }
               else
                     continue;
      }
      system("pause");
}

I haven't compiled it to check for errors. You please do it and tell me if there are any errors. Compile the code just as i have written dont add your own main function like last time :P.

koay i compiled thr are errors see in attachment And dude reason behind taking the same in both if and else is that :-- I made that to fool people that it indeed checking the pass entered So if the user entered correct so it will show wait ... And the same should also be showed in else too as its made to fool people that its checking what they entered And we don't know what they entered is true or false before checking!!

And what is the meaning of

system(pause);
And

char* getPassword();
bool checkHuman();
void displayPassword(char*);
why this?why u mentioned every function seperately?And than wrote them too?w/o that too i think program will work but i want the logic of taking this!!

And ASCII value of backspace is 127?And <37 means 1-37 no.s are all faltu characters in keyboard? and bro one more doubt if i want to erase one word too when backspace used how to do hat?Means logic would be like this?

if bacspace pressed delete last entry in the string?

And when i will try to implement it than their would be problem that everytym i have to write ths rogram or i have to create a nested loop of whole program in starting?

Link to comment
Share on other sites

koay i compiled thr are errors see in attachment

Where is the attachment?

And dude reason behind taking the same in both if and else is that :-- I made that to fool people that it indeed checking the pass entered So if the user entered correct so it will show wait ... And the same should also be showed in else too as its made to fool people that its checking what they entered And we don't know what they entered is true or false before checking!!

Look at my program i brought that code for "..." outside the if-else loop. So that means that portion of code will run for both if condition and else condition.

And what is the meaning of

system(pause);

This will write "Press any key to continue" at the end of the program. Only after the user presses a key the program will exit.

And

char* getPassword();
bool checkHuman();
void displayPassword(char*);
why this?why u mentioned every function seperately?And than wrote them too?w/o that too i think program will work but i want the logic of taking this!!

Those are the function prototypes. It is advisable to declare the function prototypes before writing the function itself. But in your case it is optional. Your program will run fine without it. But you will have to write function prototypes when you enter the software industry. The class declarations and function prototype declarations are done in the header file and the function body is written in the c/cpp files.

And ASCII value of backspace is 127?And <37 means 1-37 no.s are all faltu characters in keyboard?

Yes.

and bro one more doubt if i want to erase one word too when backspace used how to do hat?Means logic would be like this?

What do you mean by one WORD? Do you mean the last character? Look at the program i'v written. I have included that functionality. When you press backspace the last character in the string will get deleted.

And when i will try to implement it than their would be problem that everytym i have to write ths rogram or i have to create a nested loop of whole program in starting?

Implement what? I dont understand what you're saying.

Link to comment
Share on other sites

Where is the attachment?

soory for attachment i forgot to attach  :P

What do you mean by one WORD? Do you mean the last character? Look at the program i'v written. I have included that functionality. When you press backspace the last character in the string will get deleted.

by word i meant the character

Implement what? I dont understand what you're saying.

I saw ur program And understood still it was about that backspace will remove one character from string ..i undertstood now!
Link to comment
Share on other sites

@CrackUC

I forgot that C does not support boolean datatype. Wait let me change the boolean values into int.



#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>


char* getPassword();
int checkHuman();
void displayPassword(char*);


char* getPassword()
{
        char pass[21]= "";
	char ch;
	printf("Enter password(20 characters max): ");
	ch=getch();
	while((ch != '\r') && (ch != '\n'))
	{
		if((ch==127)||(ch<=31))
		{
			if(strlen(pass)>0)
			{
				printf("\b \b");
				pass[strlen(pass) -1] = '\0';
			}
		}
		else
		{
                        int len = strlen(pass);
                        if(len<20)
                        {
                            pass[len] =ch;
                            pass[len + 1] = '\0';
      			    printf("*");
                        }
		}
      			ch = getch();
		
   	}
        return pass;
}

int checkHuman()
{
       int a,b;     
       printf("\n\ntype 123 to proceed:"); /*User asked to type 123*/
       scanf("%d",&;

       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }

      if(b==123) /*If b is equal 123 than proceed or execute else part*/
      {       
             printf("\nCorrect Answer\n");
             return 1;
       }
      else
      {
             printf("\nTry Again\n");
             return 0;
       }
}

void displayPassword(char *pass)
{
       printf("\n\nType \"show\" for displaying password you have just entered :"); /*User requested to Enter show to display password entered*/
       scanf("%s",display);
       
       printf("\nwait few seconds while we proceed :");
       for(int a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }
      
      if((strcmp(displayPassword,"show")==0) 
      {       
             printf("\nCorrect Answer\n");
             printf("Your password:%s",pass); /*Dispay store info(password) in input[pass]*/
       }
      else
      {
             printf("\nTry Again\n");
             displayPassword(pass);
       }
}


int main()
{
       system("cls");
       char *password;
       password= new char[21];
       while(1)
       {
                strcpy(password,getPassword());
                if(checkHuman() == 1)
               {
                      displayPassword(password);
                      break;
               }
               else
                     continue;
      }
      system("pause");
}

Compile it and let me know if its ok.

Link to comment
Share on other sites

@CrackUC

I forgot that C does not support boolean datatype. Wait let me change the boolean values into int.



#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>


char* getPassword();
int checkHuman();
void displayPassword(char*);


char* getPassword()
{
        char pass[21]= "";
	char ch;
	printf("Enter password(20 characters max): ");
	ch=getch();
	while((ch != '\r') && (ch != '\n'))
	{
		if((ch==127)||(ch<=31))
		{
			if(strlen(pass)>0)
			{
				printf("\b \b");
				pass[strlen(pass) -1] = '\0';
			}
		}
		else
		{
                        int len = strlen(pass);
                        if(len<20)
                        {
                            pass[len] =ch;
                            pass[len + 1] = '\0';
      			    printf("*");
                        }
		}
      			ch = getch();
		
   	}
        return pass;
}

int checkHuman()
{
       int a,b;     
       printf("\n\ntype 123 to proceed:"); /*User asked to type 123*/
       scanf("%d",&;

       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }

      if(b==123) /*If b is equal 123 than proceed or execute else part*/
      {       
             printf("\nCorrect Answer\n");
             return 1;
       }
      else
      {
             printf("\nTry Again\n");
             return 0;
       }
}

void displayPassword(char *pass)
{
       printf("\n\nType \"show\" for displaying password you have just entered :"); /*User requested to Enter show to display password entered*/
       scanf("%s",display);
       
       printf("\nwait few seconds while we proceed :");
       for(int a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }
      
      if((strcmp(displayPassword,"show")==0) 
      {       
             printf("\nCorrect Answer\n");
             printf("Your password:%s",pass); /*Dispay store info(password) in input[pass]*/
       }
      else
      {
             printf("\nTry Again\n");
             displayPassword(pass);
       }
}


int main()
{
       system("cls");
       char *password;
       password= new char[21];
       while(1)
       {
                strcpy(password,getPassword());
                if(checkHuman() == 1)
               {
                      displayPassword(password);
                      break;
               }
               else
                     continue;
      }
      system("pause");
}

Compile it and let me know if its ok.

system("cls");
What u meant by this :-/

Still errors And can u write comments in ur program?

                                                  EDIT:

char pass[21][b]= "";[/b]
explain bold text y u took these?

while((ch != '\r') && (ch != '\n'))
\r means And why \n took?means a new lineshould not be thr?explain this!!

printf("\b \b");
\b means?

continue;
What it means  :-/
Link to comment
Share on other sites

system("cls");
What u meant by this :-/

It clears the screen.

Still errors And can u write comments in ur program?

                                                 

Ooops i think i missed a bracket. Let me fix that.





#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>


char* getPassword();
int checkHuman();
void displayPassword(char*);


char* getPassword()
{
        char pass[21]= "";
	char ch;
	printf("Enter password(20 characters max): ");
	ch=getch();
	while((ch != '\r') && (ch != '\n'))
	{
		if((ch==127)||(ch<=31))
		{
			if(strlen(pass)>0)
			{
				printf("\b \b");
				pass[strlen(pass) -1] = '\0';
			}
		}
		else
		{
                        int len = strlen(pass);
                        if(len<20)
                        {
                            pass[len] =ch;
                            pass[len + 1] = '\0';
      			    printf("*");
                        }
		}
      			ch = getch();
		
   	}
        return pass;
}

int checkHuman()
{
       int a,b;     
       printf("\n\ntype 123 to proceed:"); /*User asked to type 123*/
       scanf("%d",&;

       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }

      if(b==123) /*If b is equal 123 than proceed or execute else part*/
      {       
             printf("\nCorrect Answer\n");
             return 1;
       }
      else
      {
             printf("\nTry Again\n");
             return 0;
       }
}

void displayPassword(char *pass)
{
       char display[5];
       printf("\n\nType \"show\" for displaying password you have just entered :"); /*User requested to Enter show to display password entered*/
       scanf("%s",display);
       
       printf("\nwait few seconds while we proceed :");
       for(int a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }
      
      if((strcmp(display,"show")==0)) 
      {       
             printf("\nCorrect Answer\n");
             printf("Your password:%s",pass); /*Dispay store info(password) in input[pass]*/
       }
      else
      {
             printf("\nTry Again\n");
             displayPassword(pass);
       }
}


int main()
{
       system("cls");
       char *password;
       password= new char[21];
       while(1)
       {
                strcpy(password,getPassword());
                if(checkHuman() == 1)
               {
                      displayPassword(password);
                      break;
               }
               else
                     continue;
      }
      system("pause");
}

Try this. And as usual i haven't compiled this. Actually as i told you before my compiler doesn't have conio.h so i can't compile these console based programs of yours.

char pass[21][b]= "";[/b]
explain bold text y u took these?

Oh that's nothing. I just initialized an empty string using that. But your program will work without it also.

while((ch != '\r') && (ch != '\n'))
\r means And why \n took?means a new lineshould not be thr?explain this!!

\r means carriage return and \n means new line. I wasn't sure if an ENTER is treated as new line or carriage return so i placed both in the condition part. When you press enter it means you have finished typing your password. I have just implemented that logic.

printf("\b \b");
\b means?

\b stands for backspace.

continue;
What it means  :-/

It means to continue with the loop.

Link to comment
Share on other sites

It clears the screen.

Ooops i think i missed a bracket. Let me fix that.





#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<windows.h>


char* getPassword();
int checkHuman();
void displayPassword(char*);


char* getPassword()
{
        char pass[21]= "";
	char ch;
	printf("Enter password(20 characters max): ");
	ch=getch();
	while((ch != '\r') && (ch != '\n'))
	{
		if((ch==127)||(ch<=31))
		{
			if(strlen(pass)>0)
			{
				printf("\b \b");
				pass[strlen(pass) -1] = '\0';
			}
		}
		else
		{
                        int len = strlen(pass);
                        if(len<20)
                        {
                            pass[len] =ch;
                            pass[len + 1] = '\0';
      			    printf("*");
                        }
		}
      			ch = getch();
		
   	}
        return pass;
}

int checkHuman()
{
       int a,b;     
       printf("\n\ntype 123 to proceed:"); /*User asked to type 123*/
       scanf("%d",&;

       printf("\nwait few seconds while we proceed :");
       for(a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }

      if(b==123) /*If b is equal 123 than proceed or execute else part*/
      {       
             printf("\nCorrect Answer\n");
             return 1;
       }
      else
      {
             printf("\nTry Again\n");
             return 0;
       }
}

void displayPassword(char *pass)
{
       char display[5];
       printf("\n\nType \"show\" for displaying password you have just entered :"); /*User requested to Enter show to display password entered*/
       scanf("%s",display);
       
       printf("\nwait few seconds while we proceed :");
       for(int a=0;a<=5;a++)
      {
             printf(".");
             Sleep(200);
      }
      
      if((strcmp(display,"show")==0)) 
      {       
             printf("\nCorrect Answer\n");
             printf("Your password:%s",pass); /*Dispay store info(password) in input[pass]*/
       }
      else
      {
             printf("\nTry Again\n");
             displayPassword(pass);
       }
}


int main()
{
       system("cls");
       char *password;
       password= new char[21];
       while(1)
       {
                strcpy(password,getPassword());
                if(checkHuman() == 1)
               {
                      displayPassword(password);
                      break;
               }
               else
                     continue;
      }
      system("pause");
}

Try this. And as usual i haven't compiled this. Actually as i told you before my compiler doesn't have conio.h so i can't compile these console based programs of yours.

Oh that's nothing. I just initialized an empty string using that. But your program will work without it also.

\r means carriage return and \n means new line. I wasn't sure if an ENTER is treated as new line or carriage return so i placed both in the condition part. When you press enter it means you have finished typing your password. I have just implemented that logic.

\b stands for backspace.

It means to continue with the loop.

still one error And conio.h attached bro!!

And bro that system(cls); works but why clrscr(); gives error in code blocks?

And bro why you wrote

return pass;
Return pass? when pass taken? can't we use recurrtion here?we can't we call our own function in the function itself?

----

Now i tested what i said now no error but a weird problem bro function is repeating again and again using recurrtion ::reason i found your first function has some mistakes in it however i won't be able to correct them but dude u decclared to return @ the end of function that a mistake i think don't u need to declare return in else part?Because it will return when condition is not tru or say in else part and y u returning to pass?

And when u declared variable len?

Link to comment
Share on other sites

still one error And conio.h attached bro!!

And bro that system(cls); works but why clrscr(); gives error in code blocks?

I dont see any error that's just a warning. Isn't the program running?

And i can't use the conio.h file like that. The header files only contains the class/structure declarations and function prototypes. The actual function definitions are in the dll files. So i cant use the conio.h file you shared.

As i told you earlier, conio.h is not a standard c++ header and functions like gotoxy, clrscr etc are not standard c++ functions. The clrscr() function was removed from the conio.h library and so was gotoxy. So you can't use them any more. system("cls") is a system call to cls of the windows console. So it works.

Link to comment
Share on other sites

  • 9 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...