Exforsys
+ Reply to Thread
Results 1 to 5 of 5

C Program to input user name

This is a discussion on C Program to input user name within the C and C++ forums, part of the Programming Talk category; Our professor asks us to create a program that will enable a user to input a username and a password ...

  1. #1
    Rona Joana E. Anoran is offline Junior Member Array
    Join Date
    Mar 2011
    Answers
    2

    C Program to input user name



    Our professor asks us to create a program that will enable a user to input a username and a password containing 4 letters. The program will be terminated if the passwords is entered wrong for three times.. Please help.. I'm kinda lost here..

    Last edited by admin; 03-28-2011 at 07:13 AM.

  2. #2
    sujeet.varshney is offline Junior Member Array
    Join Date
    Jul 2010
    Answers
    7

    solution by sujeet director click @ career c++ expert since 1996

    Quote Originally Posted by Rona Joana E. Anoran View Post


    Our professor asks us to create a program that will enable a user to input a username and a password containing 4 letters. The program will be terminated if the passwords is entered wrong for three times.. Please help.. I'm kinda lost here..


    solution:

    Code:
     #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    
    void main()
    {
    char uid[20],pass[20];
    int p=0;
    char uoid[]="click",opass[]="sujeet";
    clrscr();
    
    int chances=3;
    
    while(chances)
    {
    cout<<"\nEnter the uid :";
    cin>>uid;
    cout<<"\nEnter the password :";
    cin>>pass;
    
    if(strcmp(uoid,uid)==0 && strcmp(pass,opass)==0)
    {
    p=1;
    break;
    }
    else
    {
    cout<<"\nInvalid uid or password";
    chances--;
    }
    
    }
    
    if(p==1)
    {
    cout<<"\nCorrect id and pass";
    }
    else
    {
    cout<<"\nyou have used all three chances ....";
    }
    
    
    
    
    getch();
    }


    Last edited by admin; 03-28-2011 at 07:02 AM.

  3. #3
    swapwarick's Avatar
    swapwarick is offline Member Array
    Join Date
    Mar 2011
    Location
    Pune,India
    Answers
    37
    Code:
    #include<iostream>
    #include<fstream>
    #include<conio.h>
    
    using namespace std;
    
    void Auth();
    void Members();
    void Userchange();
    void Passchange();
    
    string inuser;
    string inpass;
    string user;
    string pass;
    int num = 0;
    string com;
    
    main()
    {
          system("cls");
          cout<<"Welcome\n---------------------------\n\n";
          while(num==0)
          {
          system("cls");
          cout<<"Command: ";
          cin>>com;
          if(com=="login")
          {
          Auth();
          }
          else if(com=="change-pass")
          {
               Passchange();
               }
          else if(com=="change-user")
          {
               Userchange();
               }
          else if(com=="credits")
          {
               cout<<"Warrior and Venus"; // cuz it was
               }
          else if(com=="exit")
          {
               cout<<"Bye";
               getch();
               break;
               }
          else if(com==com)
          {
               cout<<"Unknown command\n";
               }
          }
    }
    void Auth()
    {
         ifstream Passfile("password.txt", ios::in);
         Passfile>>inpass;
         ifstream Userfile("username.txt", ios::in);
         Userfile>>inuser;
         system("cls");
         cout<<"USERNAME: ";
         cin>>user;
         cout<<"PASSWORD: ";
         cin>>pass;
         Userfile.close();
         Passfile.close();
         if(user==inuser&&pass==inpass)
         {
         cout<<"\nHit enter to continue to members area";
         getch();
         Members();
         }
         else
         {
             cout<<"nope";
             getch();
             main();
             }
    }
    void Userchange()
    {
         string tempass;
         system("cls");
         cout<<"enter current password: ";
         cin>>tempass;
         if(tempass==inpass)
         {
         cout<<"change username stored in file\n";
         cout<<"CHANGE USER TO: ";
         cin>>user;
         ofstream Userfile("username.txt", ios::out);
         Userfile<<user;
         Userfile.close();
         cout<<"Username successfully changed";
         getch();
         main();
    }
    else
    {
        cout<<"Invalid Password";
        getch();
        main();
    }
    }
    void Passchange()
    {
         string tempass;
         system("cls");
         cout<<"enter current password: ";
         cin>>tempass;
         if(tempass==inpass)
         {
         cout<<"utility to change password stored in file\n";
         cout<<"CHANGE PASS TO: ";
         cin>>user;
         ofstream Passfile("password.txt", ios::out);
         Passfile<<user;
         Passfile.close();
         cout<<"password successfully changed";
         getch();
         main();
    }
    else
    {
        cout<<"Invalid Password: ";
        getch();
        main();
    }
    }
    >>>>This code takes user name and password and it terminates also have look any prob so ask me! i would try more of it.

    Last edited by admin; 03-28-2011 at 07:02 AM.

  4. #4
    Rona Joana E. Anoran is offline Junior Member Array
    Join Date
    Mar 2011
    Answers
    2
    Sorry I didn't mentioned that this should be a C Language Program..


  5. #5
    swapwarick's Avatar
    swapwarick is offline Member Array
    Join Date
    Mar 2011
    Location
    Pune,India
    Answers
    37
    man...... now u can do it in C also !!!


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...