answersLogoWhite

0

  1. #include
  2. #include
  3. #include
  4. #include
  5. #define FIELD_SIZE 25
  6. #define length(array) ( sizeof (array) / sizeof (array)[i] )
  7. struct account {
  8. char *id;
  9. char *password;
  10. };
  11. static struct account accounts[] = {
  12. { "11user1", "Pwd1" },
  13. { "12user2", "Pwd2" },
  14. { "13user3", "Pwd3" }
  15. };
  16. int is_authorized ( const char *uid, const char *pwd )
  17. {
  18. int i;
  19. for ( i = 0; i < length ( accounts ); i++ ) {
  20. if ( stricmp ( uid, accounts[i].id ) == 0 &&
  21. strcmp ( pwd, accounts[i].password ) ==0 )
  22. {
  23. return 1;
  24. }
  25. }
  26. return 0;
  27. }
  28. void get_password ( char *pwd, int size )
  29. {
  30. int i = 0;
  31. int ch;
  32. while ( i < size - 1 && ( ch = getch() ) != '\r' ) {
  33. if ( ch == '\b' ) {
  34. /* Don't run off the front end of the array */
  35. if ( i != 0 ) {
  36. printf ( "\b%c\b", ' ' );
  37. --i;
  38. }
  39. }
  40. else {
  41. putchar ( '*' );
  42. pwd[i++] = (char)ch;
  43. }
  44. }
  45. pwd[i] = '\0';
  46. }
  47. int main ( void )
  48. {
  49. char uid[FIELD_SIZE];
  50. char pwd[FIELD_SIZE];
  51. printf ( "User ID: " );
  52. fflush ( stdout );
  53. if ( fgets ( uid, sizeof uid, stdin ) != NULL ) {
  54. char *newline = strchr ( uid, '\n' );
  55. /* Trim the newline if it's present */
  56. if ( newline != NULL )
  57. *newline = '\0';
  58. printf ( "Password: " );
  59. fflush ( stdout );
  60. get_password ( pwd, sizeof pwd );
  61. if ( is_authorized ( uid, pwd ) )
  62. printf("\n\n\t\tUSER AUTHENTICATED\n");
  63. else
  64. printf("\n\n\t\tINVALID USER\n");
  65. }
  66. return 0;
  67. }
User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

How do you write a C program to check whether the number is odd or even Ps-using DEV complier?

To write a C program to determine if something is odd or even you need to be a programmer. To write a program in C is complicate and only done by programmers.


Write a C program that takes a binary file as input and finds error check using different mechanisms?

write a c program that takes a binary file as input and finds error check using different mechanisms.


Write a program By using if else statement to read a number and check whether it is positive or negative?

write a c++program by using if statement to read a number and check whether it is positive or negative


Write a program to check a C?

int main (void) { if ('C' == 'C') puts ("Okay"); else puts ('Oh, gosh"); return 0; }


Can you write a C program to check whether a string is an IP address or not?

Use the Exception class and type converters.


Write a c program for creating a virus?

a c program for creat a virus


Lab manual in mca 1st sem from ignou?

write a program in C to check whether a given number is apalindrome or not


Write a c program to check whether a string follows English capitalization rules?

Active Time spent online


Where do we write main function in a c program?

Into the source program.


How do you do a username and password login program using C-language?

For a username, just get the username from the standard input using scanf and check whether this username matches with the username stored. If it doesn't match, then the username is wrong.For a password, get each character using getch(). Print a * for each character obtained. Now check this password with the stored password. If these don't match, then the password is wrong.


Write a c program to find Volume and surface area of cube?

Write a c program to compute the surface area and volume of a cube


How do you write a c program to analysis a circuit?

There is no need to write a C program for circuit analysis; there are lots of packages out there that already do that (for example, Spice).