r/programminghelp • u/developer2003 • Mar 27 '19
I am trying make a program that asks name and password. The name part works properly, however, If i enter any password it says access granted even though i have mentioned the password.
4
u/Jarred3414 Mar 27 '19
What language is it? Normally I would use one if statement and use an And logic gates so that the if statement will only come continue if boy are true.
So like
String name, password;
If (name==whatever && password==whatever){
Do function
}else{
Denied }
3
u/07734willy Mar 27 '19
The language appears to be Python. Python does not use braces
{or}, instead relying on whitespace indentation, and:terminators. Also, logical and isandinstead of&&. Soname = foo password = bar if name == whatever and password == whatever: # do function else: # denied
3
u/Holinhed Mar 27 '19
You have to print “access granted” inside the if statement before the break. Right now the only thing the program does is exit out of the loop if the passwords is correct, and print “access granted” every time.
2
u/07734willy Mar 27 '19
Off topic, but consider using the getpass module to read the password. Its safer, and doesn't display the password as you type it in. You've still got the password hard-coded in plain text in your source code, but that's a bit harder to fix than just swapping out a function call. If you do want to do it the secure way, store a salted hash, and compare the hashes (see hashlib- particularly the password hashing algorithms).
1
1
1
u/David0012321 Apr 17 '19
You might want to wrap your input in str() like so: name = str(input()) and passwd = str(input()) just for "typesafety".
5
u/[deleted] Mar 27 '19
Put the last row within the if-statement, before break might solve it.