Hi can someone tell me what hash is used by django store superuser data ? I'm asking because I'd like to pre-generate password hash, stick it into prepared json fixture and load the user automatically via script. I just need to know how to prepare particular password hash. Thanks
问问题
1635 次
3 回答
2
谢谢乔什·斯米顿。我按照你的建议做了 - 第一次手动生成密码,然后将 auth DB 转储到 json 中:
sentry --config=/etc/sentry.conf.py dumpdata --indent=2 auth > ~/auth_data.json
从转储的 json 文件中创建了一个新的夹具:
[
{
"pk": 1,
"model": "auth.user",
"fields": {
"username": "somuser",
"first_name": "Johnny",
"last_name": "Bravo",
"is_active": true,
"is_superuser": true,
"is_staff": true,
"last_login": "2012-06-24 01:13:08",
"groups": [],
"user_permissions": [],
"password": "<password_hash>",
"email": "some@someother.com",
"date_joined": "2012-06-24 01:10:30"
}
}
]
并在没有任何交互的情况下自动加载它,如下所示:
sentry --config=/etc/sentry.conf.py loaddata ~/superuser.json
于 2012-06-24T22:15:03.737 回答
0
By default user passwords are hashed using PBKDF2. You can easily change this.
The hash is stored in the format algorithm$hash
.
于 2012-06-23T00:25:37.953 回答
0
The hash used depends on the version of Django you're using. From the Django docs:
Django 1.4 introduces a new flexible password storage system and uses PBKDF2 by default. Previous versions of Django used SHA1, and other algorithms couldn't be chosen.
For more information, check out the documentation.
于 2012-06-23T00:25:58.710 回答