Python Forum

Full Version: Password Snippet
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
A crappy little password thingy, if you can find a way to implement this into anything please tell me! Big Grin Password is 180423.
print "What is the password?"
password = "180423"
if raw_input() == password:
    print "\nAccess Granted! "
else:
    print "\nAccess Denied"
Might want to check out https://docs.python.org/2.7/library/getpass.html and read up on password hashing.
(Nov-07-2016, 05:40 PM)micseydel Wrote: [ -> ]Might want to check out https://docs.python.org/2.7/library/getpass.html and read up on password hashing.
Hm. About that, I use Python 2.5 on an IPad. Long story but do you have anything else for me instead?
No.
I hate storing plaintext passwords anywhere. If it's just for you, sure, go right ahead, but once you move to doing "real" applications, using databases and storing *other peoples* info, please use a more secure method. Like a one-way hashing algorithm. For example:
>>> import hashlib
>>> hashlib.sha512('180423'.encode()).hexdigest()
'0b6c4a35b8cfb237fb16e3773cba0a65dd6af67de14f16450e857517a524f46199644add78adc3a966517ea22d7c1cc99dd716db26668b32a4e9d10b5573dc1a'
That big string is what you'd store, so your actual password isn't anywhere in your script. Then, when you get the user's password (via getpass or rawinput), you hash it, and compare the hash with what you previously computed.

That way, even if someone gets smart, they can't open up your script and read the password... (though they can re-write it, or put a different hash in there).
Hey what version of Python do you use to get .encode()) and .hexdigest()
You should find out more about the free computers available from
public libraries as suggested in a previous post. (not sure who posted)
but as I recall, these are windows 7 systems that local libraries are giving away.
I will do my best, I am just constantly busy with JROTC and homework, but thanks anyways.
(Nov-08-2016, 01:22 PM)Kai. Wrote: [ -> ]Hey what version of Python do you use to get .encode()) and .hexdigest()

Python3.  hexdigest() is just part of hashlib though, and would be used in any version of python.
(Nov-08-2016, 03:31 PM)nilamo Wrote: [ -> ]
(Nov-08-2016, 01:22 PM)Kai. Wrote: [ -> ]Hey what version of Python do you use to get .encode()) and .hexdigest()

Python3.  hexdigest() is just part of hashlib though, and would be used in any version of python.

i'm using both 2.7.12 and 3.5.2.  hashlib is there in both of these.  i have, and read, the PDF documents for the language and library (big) the helps me see what is in the versions i have running under my copy of Ubuntu 16.04 LTS.  online docs are available for many versions.