python - Django make_password too slow for creating large list of users programatically -


i need create hundreds (possibly thousands) of users programatically in django. using like:

from django.contrib.auth.models import user django.contrib.auth.hashers import make_password username, email, pwd in big_user_list:     m = user(username=username, email=email, password=make_password(pwd))     m.save() 

this taking long execute. i've confirmed make_password culprit running above script without passwords.

is there anyway around slowness issue, need script execute quickly.

you use django.contrib.auth.hashers.md5passwordhasher initial password. per django docs on how django stores passwords,

by default, django uses pbkdf2 algorithm sha256 hash, password stretching mechanism recommended nist. should sufficient users: it’s quite secure, requiring massive amounts of computing time break.

[...]

django chooses algorithm consulting password_hashers setting. list of hashing algorithm classes django installation supports. the first entry in list (that is, settings.password_hashers[0]) will used [by default] to store passwords, , other entries valid hashers can used check existing passwords. [...]

the default password_hashers is:

password_hashers = (     'django.contrib.auth.hashers.pbkdf2passwordhasher',     'django.contrib.auth.hashers.pbkdf2sha1passwordhasher',     'django.contrib.auth.hashers.bcryptpasswordhasher',     'django.contrib.auth.hashers.sha1passwordhasher',     'django.contrib.auth.hashers.md5passwordhasher',     'django.contrib.auth.hashers.cryptpasswordhasher' ) 

thus you'd want keep default now, use weaker hasher in beginning; make sure md5passwordhasher present in list. use

make_password(pwd, none, 'md5') 

to generate plain salted md5 password initially; not weak provided initial password random enough. users change passwords, passwords encrypted stronger algorithm.


Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -