Basic OS login program I have just finished the sololearn C++ course and wanted to create a basic login program in the vein of a basic operating system.

#include "ubuntu_login"
#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

Ubuntu_Login::Ubuntu_Login()
{
    cout &lt;&lt; "\t Welcome to Ubuntu!\n" &lt;&lt; endl;
}

void Ubuntu_Login::usr_login()
{

cout &lt;&lt; "Please enter a username" &lt;&lt; endl;
getline(cin,username);

cout &lt;&lt; "Please enter a password" &lt;&lt; endl;
getline(cin,password);

while(username_input != username || password_input != password)
  {
    cout &lt;&lt; "\n|Ubuntu Login|" &lt;&lt; endl;

    cout &lt;&lt; "Please enter your username" &lt;&lt; endl;
    getline(cin, username_input);

    cout &lt;&lt; "Please enter your password" &lt;&lt; endl;
    getline(cin, password_input);

    if(username_input != username || password_input != password)
      {
        cout &lt;&lt; "Incorrect username or password" &lt;&lt; endl;
      }
  }
}




#include "ubuntu_login.h"
#include &lt;iostream&gt;
#include &lt;string&gt;
using namespace std;

int main()
{
  Ubuntu_Login UO;
  UO.usr_login();
}


Header file:

#ifndef UBUNTU_LOGIN_H
#define UBUNTU_LOGIN_H
#include &lt;string&gt;
using namespace std;

class Ubuntu_Login
{
public:
  Ubuntu_Login();
  void usr_login();
private:
  string username;
  string password;
  string username_input;
  string password_input;
};

#endif // UBUNTU_LOGIN_H


Any help on improving my code by getting rid of useless code or replacing it with better code would be greatly appreciated.
Never write login code

This is much harder than you think. Leave it to the experts you will get some security piece wrong.

Code Review

Don't use this:

using namespace std;


See Why is “using namespace std;” considered bad practice?.

The reason the "standard namespace" is called std is so that it is not a big deal to type std:: before each standard object/function/type. Don't be lazy type the extra 5 characters.

I don't see declarations for username or password I hope they are not global variables.

cout &lt;&lt; "Please enter a username" &lt;&lt; endl;
getline(cin,username);

cout &lt;&lt; "Please enter a password" &lt;&lt; endl;
getline(cin,password);


You have used a while loop.

while(username_input != username || password_input != password)
{
}


You may want to look at a do while loop. As the test is not done till the end of the input code. If somebody had an empty username and password then it would match before the loop was entered and you would never get asked.

do
{
}
while(username_input != username || password_input != password);


Hint

Passwords should NEVER be stored (or encrypted). You should only ever store the hash of the password (properly salted). When a user enters a password hash it with the appropriate salt and compare it to the stored hash of the password. 

A hash can be though of as one way encryption. You can encrypt it, but because it is lossy you can not decrypt the hash back to a password. So if people get hold of the your password file all they have is a set of hashes and no passwords.