Django密码系统实现过程详解

作者:igz 时间:2022-10-13 15:55:33 

一、Django密码存储和加密方式

#算法+迭代+盐+加密

<algorithm>$<iterations>$<salt>$<hash>

默认加密方式配置


#settings里的默认配置
PASSWORD_HASHERS = [
 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
 'django.contrib.auth.hashers.Argon2PasswordHasher',
 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
 'django.contrib.auth.hashers.BCryptPasswordHasher',
]

#PASSWORD_HASHERS[0]为正在使用的加密存储方式,其他为检验密码时,可以使用的方式

默认加密方式配置

所有支持的hasher


[
 'django.contrib.auth.hashers.PBKDF2PasswordHasher',
 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',
 'django.contrib.auth.hashers.Argon2PasswordHasher',
 'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',
 'django.contrib.auth.hashers.BCryptPasswordHasher',
 'django.contrib.auth.hashers.SHA1PasswordHasher',
 'django.contrib.auth.hashers.MD5PasswordHasher',
 'django.contrib.auth.hashers.UnsaltedSHA1PasswordHasher',
 'django.contrib.auth.hashers.UnsaltedMD5PasswordHasher',
 'django.contrib.auth.hashers.CryptPasswordHasher',
]

所有支持的hasher

二、手动校验密码


#和数据库的密码进行校验
check_password(password, encoded)

#手动生成加密的密码,如果password=None,则生成的密码永远无法被check_password()
make_password(password, salt=None, hasher='default')

#检查密码是否可被check_password()
is_password_usable(encoded_password)

三、密码格式验证


AUTH_PASSWORD_VALIDATORS = [

#检验和用户信息的相似度
 {
   'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
 },

#校验密码最小长度
 {
   'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
   'OPTIONS': {
     'min_length': 9,
   }
 },

#校验是否为过于简单(容易猜)密码
 {
   'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
 },

#校验是否为纯数字
 {
   'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
 },
]

四、自定义

  • 自定义hash算法

  • 对已有hash算法升级

  • 自定义密码格式验证

官方原文

来源:https://www.cnblogs.com/igzh/p/9123781.html

标签:django,密码,系统
0
投稿

猜你喜欢

  • 详解Windows下安装Nodejs步骤

    2024-05-03 15:56:34
  • python实现神经网络感知器算法

    2021-03-06 11:23:39
  • python之DataFrame实现excel合并单元格

    2021-02-22 04:45:00
  • Python中如何将Tqdm与Asyncio结合使用呢

    2021-06-13 11:18:40
  • 一文搞懂Python中subprocess模块的使用

    2023-12-05 16:35:05
  • python中实现定制类的特殊方法总结

    2023-06-19 10:32:31
  • windows10系统中安装python3.x+scrapy教程

    2022-06-03 22:27:48
  • Golang sync包中errgroup的使用详解

    2024-02-08 23:19:08
  • Python实现图片拼接的代码

    2023-05-30 15:13:42
  • 解决Python数据可视化中文部分显示方块问题

    2021-01-27 03:53:36
  • Django使用消息提示简单的弹出个对话框实例

    2023-02-08 06:23:07
  • javascript实现简单的可随机变色网页计算器示例

    2024-04-16 09:37:07
  • 最新anaconda安装配置教程

    2021-07-17 05:05:34
  • 使用 OpenCV-Python 识别答题卡判卷功能

    2023-02-03 07:01:43
  • XMLHTTPRequest的属性和方法简介

    2007-12-18 18:42:00
  • MySQL的安全问题从安装开始说起

    2024-01-14 05:11:24
  • Pytorch实现神经网络的分类方式

    2021-02-26 05:20:47
  • Pycharm5个非常有用的方法技巧

    2023-12-03 00:19:08
  • Django中Migrate和Makemigrations实操详解

    2021-09-12 02:34:23
  • ORACLE中的的HINT详解

    2024-01-26 23:29:53
  • asp之家 网络编程 m.aspxhome.com