![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Jul 2005
Posts: 14
Rep Power: 0
![]() |
Hi. I'm new. I'm trying to use a code to make my program password protected. It keeps saying:
while password != "abcddcba": NameError: name 'password' is not defined Thanks. |
|
|
|
|
|
#2 |
|
Programmer
|
Insert this somewhere in your code (before this while loop starts)..
password="" |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jul 2005
Posts: 14
Rep Power: 0
![]() |
Thanks.
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,825
Rep Power: 5
![]() |
The password will be hidden in the source code, so people could easily retrieve it. Raise security by creating your own encrypt and decrypt function, then pre-compile the python file.
|
|
|
|
|
|
#5 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Apr 2005
Posts: 73
Rep Power: 4
![]() |
1/ You should compare encrypted/hashed strings only
2/ You should use library encryption rather than hand rolling your own. 3/ You should use library functions for other things too. Do the following in the Interactive Interpreter (etc) import md5
print md5.md5("InsertYourPasswordHere").hexdigest()copy the output (in this case 66e37426a7ff13e2957b2eed7c26039b, but obviously it'll be different for a different password) Then in your user code use: from getpass import getpass
from md5 import md5
MYPASSWORDHASH = "66e37426a7ff13e2957b2eed7c26039b" # or whatever
def get_password():
for i in range(3):
password = md5(getpass("Enter your password: "))
if password.hexdigest() == MYPASSWORDHASH:
return True
return False
def main():
if get_password():
print "Success"
# do something here
else:
print "Failure"
# do something else here
if __name__ == "__main__":
main()--OH. [Ok, md5 is theoretically breakable... =] |
|
|
|
|
|
#7 |
|
Programmer
|
Bah... if he's asking this question, I think that he is most likely not scripting something which really needs this security. I mean yeah, it's dandy and all, but is it needed?
|
|
|
|
|
|
#8 |
|
Newbie
Join Date: Jul 2005
Posts: 14
Rep Power: 0
![]() |
I'm not that advanced, just starting python. The least I can do is prevent access to the source code. How? I have no clue. I don't have to worry as long as that particular person does not have Python installed in the system. It'll open using command prompt.
|
|
|
|
|
|
#9 | |
|
Programmer
|
Quote:
|
|
|
|
|
|
|
#10 | |
|
Programming Guru
![]() Join Date: Apr 2005
Posts: 1,825
Rep Power: 5
![]() |
Quote:
He said he's new to Python, so that would probably be the easiest way for him. |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|