Python Forum
Password Snippet - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: Code sharing (https://python-forum.io/forum-5.html)
+--- Thread: Password Snippet (/thread-814.html)



Password Snippet - Kai. - Nov-07-2016

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"



RE: Password Snippet - micseydel - Nov-07-2016

Might want to check out https://docs.python.org/2.7/library/getpass.html and read up on password hashing.


RE: Password Snippet - Kai. - Nov-07-2016

(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?


RE: Password Snippet - micseydel - Nov-07-2016

No.


RE: Password Snippet - nilamo - Nov-07-2016

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).


RE: Password Snippet - Kai. - Nov-08-2016

Hey what version of Python do you use to get .encode()) and .hexdigest()


RE: Password Snippet - Larz60+ - Nov-08-2016

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.


RE: Password Snippet - Kai. - Nov-08-2016

I will do my best, I am just constantly busy with JROTC and homework, but thanks anyways.


RE: Password Snippet - nilamo - Nov-08-2016

(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.


RE: Password Snippet - Skaperen - Nov-10-2016

(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.