Skip to content

Instantly share code, notes, and snippets.

@ktoso
Created November 12, 2009 18:04
Show Gist options
  • Save ktoso/233124 to your computer and use it in GitHub Desktop.
Save ktoso/233124 to your computer and use it in GitHub Desktop.
#!/bin/env python
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# A super simple snippet to create sha1 django user passwords
#
# sample output:
# sha1$87c67$913c8d7c7f2596974c94f835c6d0f86b5b492dbf
import hashlib
import random
s1 = hashlib.sha1()
s2 = hashlib.sha1()
raw = raw_input('pass to hash: ')
s1.update(str(random.random()))
salt = s1.hexdigest()[:5]
s2.update(salt+raw)
hsh = s2.hexdigest()
algo = 'sha1'
print "%s$%s$%s" % (algo, salt, hsh)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment