Help with login code

Hi, I've been working on a login code and I was pleased that it worked perfectly until you put letters instead of numbers in the code, it just spams invalid password, how can you get it to not allow for any letters?

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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;

int main()
{
	float user, pass, newpass, pass1;		//declaring variables
	bool success1, Npass;
	for (int i = 3; i >= 0; i--)			// allows for 3 atempts
	{
		cout << "Username: ";				//print screen user and pass
		cin >> user;
		cout << "Password: ";
		cin >> pass;
		if (user != 1373145 || pass != 1234)		//while password and user dont match atempts will be counted
		{
			cout << "login failed " << i << " atempts remain" << endl;     //show amount of atempts left
			success1 = false;
		}
		else
		{
			cout << "login successful" << endl;     //successful login #1
			success1 = true;
			break;
		}
	}
	cout << "Please change your password \nNew password must consist of four digits and cannont be your default password\n";
	cout << "******************************************************************************\n";
	{
		while (success1 = true)			//if success1 is true start asking for new password
		{
			cout << "New Password: ";
			cin >> newpass;
			if (newpass == 1234)		//to not allow for same password as before
			{
				cout << "Password cannot be the same, please try again\n";
				Npass = false;

			}
			else if (newpass >= 0 && newpass <= 9999)		//must br 4 digits long
			{
				cout << "New password created \n";
				Npass = true;
				break;
			}
			else						//if anything other than 4 digits
			{
				cout << "Password invalid, please try again\n";
				Npass = false;
			}
		}

				float user1;
				if (Npass = true)
				{
					for (int A = 3; A >= 0; A--)	//new counter of 3 atempts
					{
						cout << "Username: ";
						cin >> user1;
						cout << "Password: ";
						cin >> pass1;
						if (user1 != 1373145 || pass1 != newpass)
					cout << "Login atempt failed " << A << " atempts remain\n";
				else
					cout << "*******************\n*                 *\n*                 *\n* Access granted! *\n*                 *\n*                 *\n*******************" << endl; //successful login #2!
						break;
					}
				}
	}
system("pause");
} */
Last edited on
closed account (48T7M4Gy)
pass is a float.

The error arises because strings are not integers.
Topic archived. No new replies allowed.