Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <conio.h>
- #define FIELD_SIZE 25
- #define length(array) ( sizeof (array) / sizeof (array)[i] )
- struct account
- {
- char *id;
- char *password;
- }
- static struct account accounts[] =
- {
- {
- "user", "pass"
- }
- ,
- }
- int is_authorized ( const char *uid, const char *pwd )
- {
- int i;
- for ( i = 0;
- i <
- length ( accounts );
- i++ )
- {
- if ( stricmp ( uid, accounts[i].id ) == 0 && strcmp ( pwd, accounts[i].password ) ==0 )
- {
- return 1;
- }
- }
- return 0;
- }
- void get_password ( char *pwd, int size )
- {
- int i = 0;
- int ch;
- while ( i <
- size - 1 && ( ch = getch() ) != '\r' )
- {
- if ( ch == '\b' )
- {
- if ( i != 0 )
- {
- printf ( "\b%c\b", ' ' );
- --i;
- }
- }
- else
- {
- putchar ( 'x' );
- pwd[i++] = (char)ch;
- }
- }
- pwd[i] = '\0';
- }
- int main ( void )
- {
- char uid[FIELD_SIZE];
- char pwd[FIELD_SIZE];
- int tries = 0;
- printf ("BeefOS Logon Screen \n");
- while(tries<3){//While tries is less than 3.
- if(tries==3){
- printf("\n\n\t\t 3 Failed attempts. BYE I THINK \n\a");
- return 0; //returning 0 exits the program.. i think? you can try something else to exit the program
- }
- printf ( "\n\n\t User ID: " ); //ask user for username
- fflush ( stdout ); //wait for their input?
- if ( fgets ( uid, sizeof uid, stdin ) != NULL )//assuming the input is not empty
- {
- char *newline = strchr ( uid, '\n' );
- if ( newline != NULL ) *newline = '\0';
- printf ( "\n\t Password: " );//ask for the password
- fflush ( stdout );//wait for their input?
- get_password ( pwd, sizeof pwd );//maybe do some magic too
- if ( is_authorized ( uid, pwd ) )//if the user is authorized
- {
- printf("\n\n\n\n\n\t\t Logging in. Welcome to BeefOS 0.1a");
- break;//break out of the loop, continuing our program
- }
- else //if our user is not authorized
- {
- printf("\n\n\t\t Logging in? LolNope.\n\a");
- tries = tries + 1;//increment the tries counter
- //then do nothing so that the loop happens again and it asks the user for username again
- }
- }
- }
- int integer1;
- int integer2;
- int sum;
- printf("\n\n\n\n\n Enter a digit: \n");
- scanf("%d", &integer1 );
- printf("\n Enter a digit: \n");
- scanf("%d", &integer2 );
- sum = integer1 + integer2;
- printf("The addition of these two numbers equals %d\n", sum);
- getchar();
- return 0;
- }
Add Comment
Please, Sign In to add comment