Visit Our UNIX and Linux User Community


C++ Login System help.


 
Thread Tools Search this Thread
Top Forums Programming C++ Login System help.
# 1  
Old 01-15-2011
C++ Login System help.

I'm new to C++.
I have a text file named idpw.txt which is storing id and password
e.g
admin password
account1 abc
john hello

Here's my code so far:

Code:
bool login()
{
 string user[10],password[10], user1, password1;
 ifstream myfile("idpw.txt");
 
 cout << "Please enter your username" << endl;
 cin >> user1;
 cout << "Please enter your password" << endl;
 cin >> password1;
 
 int i=0;
 int j=0;
 while (!myfile.eof())
 {
  myfile >> user[i] >> password[i];
  i++;
 }
 myfile.close();
 
 for (j=0; j<i; j++)
 {
  if (user1 == user[j] && password1 == password[j])
  {
   cout << "Successfully Login" << endl;
   return true;
  }
 }
}

I can login successfully, but here's the problem.
I want to do it in a sense that:
1) When username is correct, but password is wrong, error message will be : "Wrong Password"
2) When username is not in the list, error message will be : "No such user exist"
3) If a user typed in wrong password for 3 times, account will be locked.

Am I doing the login function right? The for loop for int j seems really wrong.
Is there a way to do this?

Thanks alot in advance.
# 2  
Old 01-15-2011
Code:
bool login()
{
 string user[10],password[10], user1, password1;
 ifstream myfile("idpw.txt");
 
 cout << "Please enter your username" << endl;
 cin >> user1;
 cout << "Please enter your password" << endl;
 cin >> password1;
 
 int i=0;
 int j=0;
 while (!myfile.eof())
 {
  myfile >> user[i] >> password[i];
  i++;
 }
 myfile.close();
 
 bool hasUser=false;

 for (j=0; j<i; j++)
 {
  if (user1 == user[j]) { 
     hasUser=true; 
     if(password1 == password[j]) {
       cout << "Successfully Login" << endl;
       return true;
     }
 }
 
 if(hasUser) { cout << "Wrong Password" << endl;
 else { cout << "No such user exist" << endl;

 return false;
}

to lock an account, you'd probably have to append the file to which accounts were locked ... or add "locked" after the "username password" in the text file.

You can loop through the whole thing 3 times and lock through it at the end if that's the case
This User Gave Thanks to rthomps7 For This Post:
# 3  
Old 01-16-2011
Thanks!

I'll go try and figure the locking up of account.
# 4  
Old 04-14-2011
Where would you put the loop if the user enters 3 times wrong username or password, how will it display again "Please enter your username" etc.
Where will the loop be?
Sorry I am new and confused...Smilie
Doesnt have to lock the account , just exit from the application.

Previous Thread | Next Thread
Test Your Knowledge in Computers #346
Difficulty: Easy
AWK was created at Bell Labs in the 1960s,
True or False?

10 More Discussions You Might Find Interesting

1. Solaris

Finding system uptime without login

Hi, Am writing a script where I want to find uptime of certain servers. Is there any command where we can find uptime without login to the server, since the server list is big logging to the server will time consuming. Thanks in advance (7 Replies)
Discussion started by: rogerben
7 Replies

2. AIX

Hanging in the system after login !

Guy's I have AIX 6.1 has some slowness when I login to the system .. When I login by user screen hangs for some time 20 seconds then it's give me the command prompt .. ! system is fine is working fine only this issue I faced can you please help me in this .. what's the expected reason... (2 Replies)
Discussion started by: ITHelper
2 Replies

3. UNIX for Dummies Questions & Answers

System list of all UNIX login accounts

What is the command to list all UNIX system login accounts? What is the command to list all system password parameters for UNIX(minimum length, complexity,age, invalid lockout attempts, expiration date , user inactivity lockout) (1 Reply)
Discussion started by: ma466
1 Replies

4. UNIX for Advanced & Expert Users

system not login

Hi, I was add my shell script in /etc/rc.d/rc.local file Eg. sh /root/KernelModule.sh my KernelModule.sh contain insmod xxxxx.ko insmod yyyy.ko I have insmod 22 kernelmodule in this script , all the modules are my own driver modules. now problem is my system is booting but... (2 Replies)
Discussion started by: rajamohan
2 Replies

5. Shell Programming and Scripting

How can i use system users in perl for login page

Hi, I want to code a script with perl. For this, I need some knowledge. How can i use system user name(with group) and password in my login page? I will be happy if you can help me (2 Replies)
Discussion started by: tahsinaltay
2 Replies

6. Solaris

how do you login as sms-svc on a system controller

hi, i have got a SUN F15K DOMAIN TAKING HARDWARE CONFIGURATION DUMP. DUMP FILE: -D/VA message i wnat to logon as sms-svc on to the controller to check what's happening can you please guide me how do i login as sms-svc on the controller and check thank you (1 Reply)
Discussion started by: vinix
1 Replies

7. HP-UX

Prompted for System Password during login

Hello, I'm new to HP-UX. I have a system running B.11.23 on ia64. The system gets its user passwords via active directory. Everytime a new account is added to AD a script pushes out the account info to all the systems and this system is updated too. However, on this machine, users are unable to... (2 Replies)
Discussion started by: BFLO
2 Replies

8. Cybersecurity

Disablin login for system accounts

Hy everyone! I'm trying to lock out system accounts on my Tru64 UNIX machines. Wherever I look, it says only to put Nologin or *Nologin in password field of desired account in /etc/passwd. But it doesn't work. I still can su to that accounts. There are some accounts that already have Nologin... (1 Reply)
Discussion started by: veccinho
1 Replies

9. Solaris

How to check the last login user were doing in the system

Hi, I'm new to solaris/ Unix and would like to know how to check in the system what was the last login user were doing. Is there any way to check this? Thanks in advanced. (1 Reply)
Discussion started by: raziayub
1 Replies

10. UNIX for Dummies Questions & Answers

past login still exist in the system

hi, i noticed that there are still past logins which have not been terminated. how should i removed them? i am on aix. (9 Replies)
Discussion started by: yls177
9 Replies

Featured Tech Videos