
- Forum
- Programming Talk
- C and C++
- C Program to input user name
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 ...
-
03-27-2011, 12:56 AM #1
- 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.
-
03-27-2011, 11:06 AM #2
- Join Date
- Jul 2010
- Answers
- 7
solution by sujeet director click @ career c++ expert since 1996
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.
-
03-27-2011, 03:13 PM #3>>>>This code takes user name and password and it terminates also have look any prob so ask me! i would try more of it.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(); } }
Last edited by admin; 03-28-2011 at 07:02 AM.
-
03-29-2011, 11:01 PM #4
- Join Date
- Mar 2011
- Answers
- 2
Sorry I didn't mentioned that this should be a C Language Program..
-
03-30-2011, 01:11 PM #5
man...... now u can do it in C also !!!
-
Sponsored Ads

Reply With Quote






