Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Snippet
#1
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"
The K Man.
Reply
#2
Might want to check out https://docs.python.org/2.7/library/getpass.html and read up on password hashing.
Reply
#3
(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?
The K Man.
Reply
#4
No.
Reply
#5
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).
Reply
#6
Hey what version of Python do you use to get .encode()) and .hexdigest()
The K Man.
Reply
#7
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.
Reply
#8
I will do my best, I am just constantly busy with JROTC and homework, but thanks anyways.
The K Man.
Reply
#9
(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.
Reply
#10
(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.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Advanced CLI Snippet Manager bytebutcher 1 2,604 Sep-20-2020, 11:58 AM
Last Post: bytebutcher
  Checkbox snippet menator01 0 2,366 May-16-2020, 08:26 AM
Last Post: menator01
  Cute oscillating range generation snippet I saw on irc league55 1 2,766 Mar-26-2018, 04:19 PM
Last Post: nilamo
  snippet: dp and pv Skaperen 0 2,932 Apr-08-2017, 07:17 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020