TechTorch TechTorch - 1 year ago 55
Python Question

My script will not work, not sure if i am doing python right

So for some odd reason my code wont work in visual studios on my laptop. it gives me errors on my script. Am i doing it wrong. The errors i got were:

  • cant assign to errorexpression --Line 2

  • unexpedcted indent --Line 2

  • unexpected token '' --line 6

    print("welcome user")
    varpassword = input("Please enter a password: ")
    if varpassword = "thisisthepassword123":
    print("access denied")

Answer Source

As others have pointed out your conditional statement should use the == operator (to indicate that you are comparing the two values to see if they're equal) instead of = that assigns the value to the variable.

if varpassword = "thisisthepassword123":

I just want to add that you should avoid using a hard-coded password value especially in python since it's plain text (unless this is just sample code to illustrate)


Use a hashing algorithm to hash your password instead and then hash the user input and compare that. So you'll put the password through something like SHA1 or so (if you want to use a hard-coded value like "thisisthepassword123" it will have a value of f61c1bbcf1f7d68106a18bd753d4fc3c4925793f. So using a library like hashlib( you can do this:

import hashlib

Also consider using salting, read this:

Edit 2:

Also make sure that your indentation in your script matches the indentation of your code snippet

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download