[英]python regex for password validation
我有以下要求來驗證以下上下文的密碼
下面的程序正在進行部分匹配,但不是完整的正則表達式
#!/usr/sfw/bin/python
import re
password = raw_input("Enter string to test: ")
if re.match(r'[A-Za-z0-9@#$]{6,12}', password):
print "match"
else:
print "Not Match"
正在使用:
localhost@user1$ ./pass.py
Enter string to test: abcdabcd
match
它正在評估錯誤的輸出。 任何人都可以在這里建議我應該使用re.search
嗎?
這是至少一位數字、一位大寫字母、至少一位小寫字母、至少一位特殊字符的正則表達式
import re
password = input("Enter string to test: ")
# Add any special characters as your wish I used only #@$
if re.match(r"^(?=.*[\d])(?=.*[A-Z])(?=.*[a-z])(?=.*[@#$])[\w\d@#$]{6,12}$", password):
print ("match")
else:
print ("Not Match")
希望能幫到你...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.