Thread: How to create login and password?

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    31

    How to create login and password?

    hi guys...

    Im currently doing a project on a search and sort student database.Im required to create login and password for the users before he can enter the database.May i know how can i do that in C programming?

    Also, there are 3 categories of users----> Students, Lecturers and Guests.

    The criterias are:
    For Student: He can only see his own info only, not others.
    For Lecturer: He can see all in database.
    For Guest:He cannot see the student's grades.

    In the question given, there's only 13 students in the database.What is the optimal way to implement this database?
    m planning to use sequential search + arrays + structures.Is it good?

    Hope to get some clue here...As my project is gonna due at the end of this month!thanks alot..

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    That sounds like a good way to do it.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Something like this . . .
    Code:
    struct student_t {
        char name[BUFSIZ], password[BUFSIZ];
    } user[13];
    
    for(x = 0; x < 13; x++) {
        if(student == user[x]) {}
    }
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Sep 2005
    Posts
    31
    Thanks for replying me, dwks...
    Code:
    if(student == user[x]) {}
    For the above code, what should i include in between the curly braces?
    Should i initialize student ?

  5. #5
    Registered User vinit's Avatar
    Join Date
    Apr 2006
    Location
    India
    Posts
    39
    U can store all student related info here.
    Code:
    struct student_info {
     int rollno;
     char name[30];
     /* Other required fields*/
    };
    All passwords & username fields stay here
    Code:
    struct authentication {
    char username[10],password[10];
    int category;  /* 0 = student,1=teacher,2=guest */
    };
    Once user gets login then call display function with rollno & category,
    Code:
    void display(int rollno,int category) { 
    /* here u can write conditions for viewing i.e. if user is student then he will see only his data */
     for(x = 0; x < 13; x++) {
        if(rollno == user[x].rollno) { /* display all structure fields */
        }
      }
    
    /* And so on for other categories */
    }
    if we consider the database is sorted according to roll no then u can acquire data in single shot just by indexing array with key as rollno




    Thanks & Regards
    Vinit
    Last edited by vinit; 04-10-2006 at 02:26 AM.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    31
    thanx alot Vinit!

    I guess i kinda understand bout how it functions.But still have to try it myself..

    My friend has suggested that I should use file to create this student database,he said it will be better because arrays has temporary memory.What do you think?
    If file is better, how can i create a database using file?How many files do i need, as there are 3 different conditions for 3 different types of user?I don't know how to set the conditions...

    Sorry for asking oo much here, im a newbie who know very little, maybe anyone can kindly give me some good website to refer regarding my project..Thanks a million!

  7. #7
    Registered User vinit's Avatar
    Join Date
    Apr 2006
    Location
    India
    Posts
    39
    Yes indeed files will provide persistant storage.
    U can use following file functions
    fopen(); //opening file
    fread(); //read from file
    fwrite(); //write to file
    fclose(); //close file
    find their help & use them.

  8. #8
    Registered User
    Join Date
    Sep 2005
    Posts
    31
    #include<stdio.h>
    #define MNAME 20

    struct Login{
    char name[MNAME];
    char password[MNAME];
    };

    int main(void){

    struct Login student[3]={{"sherwi","8379008"},{"chris","smileyshen"},{"sh erwi10","cspang86"}};
    struct Login lecturer[2]={{"Ian","Chai"},{"hcling","hc988"}};
    struct Login query;

    int user,i;

    printf("Login as...\n");
    printf("[1]Student [2]Lecturer [3]Guest\n");

    scanf("%d",&user);

    switch(user){

    case 1: case 2:
    printf("Username:");
    scanf("%s",query.name);
    printf("Password:");
    scanf("%s",query.password);

    for(i=0;i<3;i++){{
    if(query.name==student[i].name)
    printf("Login Successful");
    }
    if(query.name!=student[i].name)
    printf("Wrong username or password");
    exit(1);
    }
    break;

    case 3:
    printf("You can enter without login");

    break;

    default:
    printf("Invalid input");
    exit(1);

    break;
    }

    return 0;
    }


    [QUOTE]

    This is what i've done for the login part.But i cant seem to get the right output.I think most probably my if condition is wrong.Can anyone tell me what is the right condition ??

  9. #9
    Registered User vinit's Avatar
    Join Date
    Apr 2006
    Location
    India
    Posts
    39
    well u should compare string using strcmpi() function,& store those password & username in seperate file.
    Code:
     if (strcmpi(query.name,student[i].name) == 0) {
     printf("\nLoging successful");
    }
    In case strcmpi gives error use strcmp instead.

  10. #10
    Registered User
    Join Date
    Sep 2005
    Posts
    31
    case 1: case 2:
    printf("Username:");
    scanf("%s",query.name);
    printf("Password:");
    scanf("%s",query.password);

    for(i=0;i<3;i++){
    if(strcmp(query.name,student[i].name)==0 && strcmp(query.password,student[i].password)==0)
    printf("Login Successful");
    }


    break;


    ok, i've changed to this...But one question, how do i tell the program to exit when the username and password is wrong?

    and for the type of user, instead of typing 1,2 or 3 or any other integers, when i type a character or a string, it will proceed to asking for username and password when it should be an invalid input.Do u know what's wrong?

  11. #11
    Shibby willc0de4food's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    378
    Code:
     for(i=0;i<3;i++){
    if(strcmp(query.name,student[i].name)==0 && strcmp(query.password,student[i].password)==0)
    { printf("Login Successful"); }
    else
    {
     if (i == 2) /*its the 3rd try and failed */
     { return 0; }
    }
    Registered Linux User #380033. Be counted: http://counter.li.org

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A tenet connection from a C program..
    By ahmd2080 in forum Linux Programming
    Replies: 2
    Last Post: 07-04-2009, 03:42 AM
  2. login and password & printing
    By raithedavion in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2006, 11:19 AM
  3. simple login program problem
    By suckss in forum C Programming
    Replies: 11
    Last Post: 11-11-2006, 05:02 PM
  4. Security Login Daemon
    By curlious in forum C++ Programming
    Replies: 7
    Last Post: 04-29-2005, 03:31 PM
  5. login script - URGENT!!!
    By linzeeuk in forum C Programming
    Replies: 5
    Last Post: 05-05-2003, 02:26 PM