Answers for "django set password"

0

django change user password

python manage.py shell

from django.contrib.auth.models import User

usr = User.objects.get(username='your username')
usr.set_password('raw password')
usr.save()
Posted by: Guest on December-23-2020
2

django change password command line

python manage.py changepassword <user_name>
Posted by: Guest on September-04-2020
0

password in django

from django.db import migrations

from ..hashers import PBKDF2WrappedSHA1PasswordHasher


def forwards_func(apps, schema_editor):
    User = apps.get_model('auth', 'User')
    users = User.objects.filter(password__startswith='sha1$')
    hasher = PBKDF2WrappedSHA1PasswordHasher()
    for user in users:
        algorithm, salt, sha1_hash = user.password.split('$', 2)
        user.password = hasher.encode_sha1_hash(sha1_hash, salt)
        user.save(update_fields=['password'])


class Migration(migrations.Migration):

    dependencies = [
        ('accounts', '0001_initial'),
        # replace this with the latest migration in contrib.auth
        ('auth', '####_migration_name'),
    ]

    operations = [
        migrations.RunPython(forwards_func),
    ]
Posted by: Guest on June-15-2021

Python Answers by Framework

Browse Popular Code Answers by Language