URL: https://linuxfr.org/forums/astucesdivers/posts/admin-construire-des-mots-de-passe-forts-mais-facilement-recon Title: [Admin] Construire des mots de passe forts mais facilement reconstructibles Authors: Olivier Grisel Date: 2007年11月10日T15:59:19+01:00 Tags: Score: 1 Voici un petit script en python qui construit des mots de passe forts (pas dans les dictionnaires) en prenant les 8 premiers caractères de la version base64 du digest hexadécimal sha de la concaténation d'un mot de passe maitre (unique) faible mais simple à retenir et d'une clef specifique au domaine d'utilisation du mot de passe (typiquement le nom du service ou de la machine). Cette méthode permet de construire un ensemble illimité de mot de passe à partir d'un mot de passe maitre unique donc facilement mémorisable pour pouvoir retrouver tous les autres en cas d'oublis. La base64 sert à avoir une distribution des caractères sur l'alphabet complet (majuscules et minuscule) + les characteres numeriques. Voici donc mkpasswd.py #!/usr/bin/python """Utility script to build a set of strong yet rebuildable passwords The final password is build from a potentialy weak but easy to remember yet secret master password and a domain-specific key like the name of the website you are building a password for. The password is then the 8th first characters of the base64 encoding of hexadecimal sha digest of the concatenation of the master seed and the domain key:: >>> make_password("foobar", "amazon") 'YWRjM2Fl' >>> make_password("foobar", "paypal") 'MzM2Yzhm' >>> make_password("foobar", "paypal", lowercase=True) 'mzm2yzhm' :author: Olivier Grisel <olivier.grisel@ensta.org> This script is placed in the Public Domain: http://creativecommons.org/licenses/publicdomain/ """ import sha, base64 LENGTH = 8 LOWERCASE = False def make_password(master_seed, domain_key, lowercase=LOWERCASE): hash = sha.new(master_seed + domain_key).hexdigest() password = base64.b64encode(hash)[:LENGTH] if lowercase: return password.lower() else: return password def main(): # seed and domain prefix are read interactively from stdin to avoid # password data to be stored in the shell command history master_seed = raw_input("master seed: ") domain_key = raw_input("domain key [e.g. 'paypal']: ") print "your password is:", make_password(master_seed, domain_key) def _test(): import doctest doctest.testmod() if __name__ == "__main__": import sys if len(sys.argv) > 1 and sys.argv[1] == "--selftest": _test() else: main() Utilisation: $ python mkpasswd.py Pour lancer les tests: $ python mkpasswd.py --selftest