Imagine the current password for the administrator of a serv

Imagine the current password for the administrator of a server is “as1987Jantu35*^ft$TTTdyuHi28Mary”.

Write a program for checking the password to login as the admin. Your program should ask the user to insert the password to access to the server. If the user inserts the correct password, print “You have successfully logged in to the server as an admin “, if not, give the user 3 other chances to try to insert the password.

Ok, here is my code, I know it isn\'t finished but it keeps giving me an error of \"ValueError: invalid literal for int() with base 10: \'text\'\"

LARGE_PRIME = 541
_KEY = 31
MAX_FAILURES = 3

num_failures = 0


while num_failures < MAX_FAILURES:

login_str = int(input(\"Please enter the password: \"))
login= hash(login_str)%LARGE_PRIME

  
if login== _KEY:
print (\"Correct!\")
break   
else:
num_failures = num_failures + 1
print (\"Incorrect! You have failed\", num_failures, \"times.\")

if num_failures >= MAX_FAILURES:
print (\"Sorry, you have hit the maximum number of failures allowed.\")

Please explain what you did to fix it. Also, no imports, if possible.

Solution

The error is in below line,
login_str = int(input(\"Please enter the password: \"))

here, you are using \'int\' type to read input of password. But the password should be string, because it contains alphanumeric values.
so you should use like,
login_str = input(\"Please enter the password: \")
or
login_str = raw_input(\"Please enter the password: \")

Imagine the current password for the administrator of a server is “as1987Jantu35*^ft$TTTdyuHi28Mary”. Write a program for checking the password to login as the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site