from fastapi import FastAPI
import re
app = FastAPI(
title="Fastapi弱密码检测",
description="这是一个弱密码检测api"
)
def pass_word_validation(password: str):
result = re.search(r"^[\w]{6,16}$", password) # 弱密码验证
# result = re.search(r"^.*(?=.{6,})(?=.*\d)(?=.*[A-Z])(?=.*[a-z])(?=.*[!@\.#$%^&*? ]).*$", password) # 强密码验证
if result:
return "密码创建成功"
return "密码长度必须为6位以上字母或数字组合"
# return "密码至少为6位,且包括至少1个大写字母,1个小写字母,1个数字,1个特殊字符"
@app.post("/password_validation/", description="弱密码检测")
async def password_validation(password: str):
return pass_word_validation(password)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app="passowrd_validation:app", host="127.0.0.1", port=8000, reload=True)
Python学习日志01——Fastapi弱密码与强密码检测
最新推荐文章于 2024-06-18 11:50:36 发布