utf-8、pbkdf2_sha

#utf-8加密、解密

import base64

base64.b64encode('lienlien123'.encode('utf-8'))

b'bGllbmxpZW4xMjM='

base64.b64decode(b'bGllbmxpZW4xMjM='.decode('utf-8'))

b'lienlien123'

#pbkdf2_sha加密,校验

该种密码在不同时刻会有产生不同的加密结果

该加密方法使用的是散列消息,所以加密是不可逆的,

只能通过校验验证密码加密解密后是否一致,不可解密

PASSWORD_HASHERS = (

'django.contrib.auth.hashers.PBKDF2PasswordHasher',

'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher',

'django.contrib.auth.hashers.BCryptSHA256PasswordHasher',

'django.contrib.auth.hashers.BCryptPasswordHasher',

'django.contrib.auth.hashers.SHA1PasswordHasher',

'django.contrib.auth.hashers.MD5PasswordHasher',

'django.contrib.auth.hashers.CryptPasswordHasher',

)

from django.contrib.auth.hashers import make_password, check_password

pwd='lienlien123'

产生加密后密码

make_password()的第二位参数为None时,每次产生的加密结果都不一样,

当加入任意参数时,既可以相同

mpwd=make_password(pwd,None,'pbkdf2_sha256')

校验加密后是否相同

pwd_bool=check_password(pwd,mpwd)

print(pwd_bool)

相关推荐
2401_828890649 分钟前
使用 BERT 实现意图理解和实体识别
人工智能·python·自然语言处理·bert·transformer
多恩Stone1 小时前
【3DV 进阶-2】Hunyuan3D2.1 训练代码详细理解下-数据读取流程
人工智能·python·算法·3d·aigc
xiaopengbc2 小时前
在 Python 中实现观察者模式的具体步骤是什么?
开发语言·python·观察者模式
Python大数据分析@2 小时前
python用selenium怎么规避检测?
开发语言·python·selenium·网络爬虫
ThreeAu.2 小时前
Miniconda3搭建Selenium的python虚拟环境全攻略
开发语言·python·selenium·minicoda·python环境配置
偷心伊普西隆2 小时前
Python EXCEL 理论探究:格式转换时处理缺失值方法
python·excel
精灵vector3 小时前
LLMCompiler:基于LangGraph的并行化Agent架构高效实现
人工智能·python·langchain
java1234_小锋3 小时前
Scikit-learn Python机器学习 - 特征降维 压缩数据 - 特征选择 - 移除低方差特征(VarianceThreshold)
python·机器学习·scikit-learn