How to create user from django shell

前端 未结 7 478
借酒劲吻你
借酒劲吻你 2021-01-30 04:13

When i create user from django-admin user password\'s are encrypted . but when i create user from django shell user-pasword is saved in plain text . Example :

7条回答
  •  情话喂你
    2021-01-30 04:23

    There are couple of way to set password for a django user object from django-shell.

    user = User(username="django", password = "secret")
    user.save()
    

    This will store encrypted password.

    user = User(username="django")
    user.set_password("secret")
    user.save()
    

    This will store encrypted password.

    But,

    user = User(username="django")
    user.password="secret"
    user.save()
    

    This will store plain text password. There is no hashing / encryptions applied since you are modifying the property directly.

提交回复
热议问题