有勇气的牛排博客
☰

python 非法字符处理

有勇气的牛排 1050 Python 2023-05-18 20:45:36

知止自律打卡-微信小程序APP
一款微信自律打卡小程序,支持自定义打卡项目、习惯记录、项目日记、专注计时与数据统计。自律打卡、学习打卡、读书打卡、健身打卡、运动打卡、减肥打卡、戒色打卡、养生打卡、戒烟、戒酒、戒熬夜等多种场景。万能打卡模板自由创建。可自定义每日打卡目标,记录习惯连续天数,可视化追踪成长进度。
了解产品详情 →
微信搜索「知止自律打卡」
知止自律打卡微信小程序

过滤非法字符

def sql_filter(sql, max_length=20): dirty_stuff = ["\"", "\\", "/", "|", "&", "*", "'", "=", "-", "#", ";", "<", ">", "+", "%", "$", "(", ")", "%", "@","!"] for stuff in dirty_stuff: sql = sql.replace(stuff, "") return sql[:max_length] username = "1234567890!@#!@#!@#$%======$%|&***" username = sql_filter(username) # SQL注入 print(username) # 输出结果是:1234567890

检测是否包含非法字符

import re # username = "1234567890!@#!@#!@#$%======$%|&***" username = "1234567890*" # 检测到非法字符进入if if not re.search(u'^[_a-zA-Z0-9\u4e00-\u9fa5]+$', username): msg = u"用户名不可以包含非法字符(!,@,#,$,%...)" print(msg)

参考:
https://www.cnblogs.com/cybermat/articles/473314.html
https://blog.csdn.net/weixin_30707875/article/details/99341309

评论区

×
×