repl.it
@ArlanPereira/

Login attempts

C++

No description

fork
loading
Files
  • main.cpp
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <iostream>
#include<string>
using namespace std;

int main() {
  
  int loginAttempts = 0;
  bool running = true;
  string username = "Boris";
  string password = "Paris";
  string usernameEntered;
  string passwordEntered;
  cout << "Login Script" << endl;
  while(running){
    if(loginAttempts >= 3){
      cout << "Too many failed attempts. Locking you out" << endl;
      running = false;
      break;
    }
  cout << "Please enter your username" << endl;
  cin >> usernameEntered;
  cout << "Please enter your password" << endl;
  cin >> passwordEntered;
  if(usernameEntered == username && passwordEntered == password){
    cout << "Login successful" << endl;
    running = false;
    break;
  }else{
    cout << "Login incorrect. Please try again" << endl;
    loginAttempts +=1;
  }
  }
}