Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] [moved] Regarding password changing function in C

Status
Not open for further replies.

achar.deepak

Member level 1
Joined
Dec 12, 2016
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
415
Dear All,

I have written a code for password managing function in C. I need to change the password from default password. I have attached my code. The password is not updating. Please help. Thanks in advance.

Code:
#include <stdio.h>
#include <string.h>
#include <conio.h>
#include <stdlib.h>

char loginpassword[10];
int Current_mode = 2;
int num;
int value_store;

void change_password(void);
char *Password_Ascii_function(void);

int main (void)

{

	printf("Password Manager:\n");

	char defaultascii[5] = "1234", count;
	
	char *returnacii;

	strcpy(loginpassword ,"Enter Password");
	
	printf(loginpassword);

	printf("\n");

	while(1)
	{

			returnacii = Password_Ascii_function();	
		
	   		if(strcmp(returnacii, defaultascii)==0)
       		{	
       			returnacii[0] = '0';
       			returnacii[1] = '0';
       			returnacii[2] = '0';
				returnacii[3] = '0';
       			       			
       			strcpy(loginpassword, "Enter New Password");

				printf("\n");
			    
				printf(loginpassword);

				printf("\n");
                
				returnacii = Password_Ascii_function();
                
                defaultascii[0] = returnacii[0];
                defaultascii[1] = returnacii[1];
				defaultascii[2] = returnacii[2];
                defaultascii[3] = returnacii[3];

				printf("\n");
                
                printf("Password changed, Login again:");

				printf("\n");

                main();                    
            }
            else
	 		{
	  			strcpy(loginpassword,"Wrong Password");
					  			
				count=count+1;
        	
				if(count>=4)
        		{
	           		strcpy(loginpassword,"Default Password");
            	    
					printf(loginpassword);
										
					defaultascii[0] = '1';
            		defaultascii[1] = '2';
            		defaultascii[2] = '3';
            		defaultascii[3] = '4';
            		defaultascii[4] = '\0';            			
            		
					strcpy(loginpassword, defaultascii);
                }
	  		 }

		printf(loginpassword);
				
	}

	getch();
	return 0;
}

char *Password_Ascii_function(void)
{
	
	char pasword[10],usrname[10], ch;
    int i;
 
      for(i=0;i<4;i++)
        {
			ch = getch();
			pasword[i] = ch;
			ch = '*' ;
			printf("%c",ch);
		}
 
       pasword[i] = '\0';

       return pasword;

}

Regards
Deepak A B C
 

You are not updating the new password at the flash memory.
Your code will allways retrieve the default password.
 

Hi,

I am not using any flash memory here. Please help.

Thanks
Deepak
 

char *Password_Ascii_function(void);
Try chaging that to: void Password_Ascii_function ( char * ) where you send "returnacii" directly as an argument on the function and you modify it.

If I remember right, the below ones in the function will be destroyed after the function is over. So the "return password" is basically "trash".
char pasword[10],usrname[10], ch;
 

Hi,

Here I am getting error as Password_Ascii_function: Function does not take 0 arguments. Please help.

Thanks
Deepak
 

Considering that the password has invariably 4 digits, why do are you adding extra complexity to the code by using pointer to function, whereas this could be achieved in a simplest fashion just by using global variables instead ?
 

why there is an extra call to main() in your code ?
 

Anyway, the code as a whole need to be deeply reviewed.
For example, the following function:
Code:
strcpy(loginpassword ,"Enter Password");
Is going to load an array of 14 characters at a variable loginpassword previously declared as having 10 bytes lenght.
 

Talking about errors, I hope the OP was joking here:
Code:
printf(loginpassword);
And many others... In a nutshell, that code is far from working.
 

Hi andre_teprom

Thanks. I got the solution.

Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top