Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
page title tags date
Pre-Hashing Passwords In Python
python mysql linux
2015-11-27

Hashing passwords beforehand which will be used in scripts or other places can be useful. It allows you to store the hashed value for later use, but keep the original password securely stored elsewhere. Here's how to hash passwords in Python for Unix user accounts and MySQL users.

Unix Password

import crypt
pwd = "MY SECURE PASSWORD"
# yes, the literal string 'password' is the salt
hashed = crypt.crypt(pwd, "password")
print(hashed)

Set the password on a user with usermod

PASSWORD=$(./codefromabove.py)
usermod --password "$PASSWORD" myuser

MySQL Password

import hashlib
# mysql pwd is two iterations of sha1
first = hashlib.sha1(pwd.encode('ascii'))
second = hashlib.sha1(first.digest())
return "*" + second.hexdigest().upper()

Apply it to a user in mysql query

CREATE USER 'myuser'@'localhost' IDENTIFIED BY PASSWORD '{hashed_value_goes_here}';

About

No description, website, or topics provided.

Resources

Releases

No releases published

Packages

No packages published