Esempio n. 1
0
 def set_user_password(self, user, plaintext):
     '''
     设置用户密码
     '''
     user.password = encrypt_password(
         plaintext, encryption=settings.PASSWORD_ENCRYPTION)
     user.save()
Esempio n. 2
0
    def test_pwd_encrypt_verify(self):
        plaintext = 'password'
        ciphertext = encrypt_password(plaintext, 'MD5')
        self.assertTrue(verify_password(plaintext, ciphertext))

        ciphertext = encrypt_password(plaintext, 'SMD5')
        self.assertTrue(verify_password(plaintext, ciphertext))

        ciphertext = encrypt_password(plaintext, 'SHA')
        self.assertTrue(verify_password(plaintext, ciphertext))

        ciphertext = encrypt_password(plaintext, 'SSHA')
        self.assertTrue(verify_password(plaintext, ciphertext))

        with self.assertRaises(ValueError):
            ciphertext = encrypt_password(plaintext, 'PLAINTEXT')
Esempio n. 3
0
 def create_user(cls, username, password):
     '''
     创建用户
     '''
     return cls.objects.create(
         username=username,
         password=encrypt_password(password, settings.PASSWORD_ENCRYPTION),
     )
Esempio n. 4
0
 def set_user_password(self, user, plaintext):
     '''
     更新用户密码
     '''
     dn = user.dn
     self.conn.patch(
         dn, {
             'userPassword':
             encrypt_password(plaintext, settings.PASSWORD_ENCRYPTION)
         })
Esempio n. 5
0
def create_admin_user(apps, schema_editor):
    '''
    创建管理员
    '''
    User = apps.get_model('oneid_meta', 'User')
    UserPerm = apps.get_model('oneid_meta', 'UserPerm')
    Perm = apps.get_model('oneid_meta', 'Perm')
    admin = User.objects.create(
        username='******',
        password=encrypt_password(settings.WEB_ADMIN_PASSWORD, settings.PASSWORD_ENCRYPTION),
    )
    UserPerm.objects.create(
        owner=admin,
        perm=Perm.objects.get(uid=ADMIN_ACCESS_PERM),
        status=1,
        value=True,
    )