home *** CD-ROM | disk | FTP | other *** search
- /* This program will ask for a password from the user.
- if the password is incorrect the program goes round
- again. */
-
- #include <string.h>
- #include <stdio.h>
-
- /* The main function */
-
- void main()
- {
- char c,input[10],pass[10];
- char *p_pass,*p_input;
- int counter,result;
-
- /* Call the routine to read the password from disk */
-
- readpass(pass);
- p_pass=pass;
- p_input=input;
-
- /* The main program loop. Waits for the correct password */
-
- do
- {
- counter=0;
- input[0]='\0';
-
- printf("\33cPlease enter the password:\n\33[8m");
-
- /* Get the users input */
-
- do
- {
- c=getchar();
- input[counter]=c;
- ++counter;
- }
- while(c!='\n' && counter!=10);
- input[counter-1]='\0';
- printf("\33[0m");
-
- /* Check the two strings. result=0 means same. */
-
- result=strcmp(p_pass,p_input);
- }
- while(result!=0);
- }
-
- /* The routine to read the 'word' file containing the password */
-
- int readpass(got)
- char got[10];
- {
- FILE *in_file, *fopen();
- int c,count;
- count=0;
-
- /* Open the file */
-
- in_file=fopen("word","r");
- if(in_file==NULL)
- {
- printf("Sorry there is no password file!\n");
- exit(0);
- }
- else
- {
-
- /* Read the password */
-
- while((c=getc(in_file))!=EOF)
- {
- got[count]=c;
- ++count;
- }
-
- /* Return the password to the main() function and
- end the routine */
-
- got[count-1]='\0';
- return(got);
- }
- }
-