密碼強度驗證

  • 44
  • 0

用ASP 做密碼強度的檢驗, 用 regExp ( 正規 )

<!DOCTYPE html>
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
	<link rel="stylesheet" href="http://at.alicdn.com/t/font_626784_0j006ef09vff.css">
	<script src="https://cdn.staticfile.org/jquery/1.11.2/jquery.min.js"></script>
	<title>asp密碼複雜度函數</title>
</head>
<style>
input{width:600px; height: 50px; line-height: 50px; font-size: 16px; font-family:微軟雅黑;}
</style>
<body>
<form action="login_check.asp" method="post">
<input type="text" placeholder="請輸入密碼,長度要求8位以上,必須包含數字、字母及特殊字符" name="pass"  value="<%=request("pass")%>">
<br><input type="submit" id="tijiao" value="提交">
</form>
<%
if request("pass")<>"" then
	check_resualt = checkPass(request("pass"))	
end if
function checkPass(strPass)
	strReturn = ""
	if len(strPass)<8 then
		'strReturn = len(strPass)
		strReturn="pwd must be 8"						'密碼長度必須八位以上
	elseif not regTest(strPass,"[a-zA-Z]") then
		strReturn="pwd , english!"	'密碼必須包含字母
	elseif not regTest(strPass,"\d") then
		strReturn="pwd must contant number"				'密碼必須包含數字
	elseif not regTest(strPass,"[~!@#$%^&*`()_+=/<>,./?:"";'\-\\\{\}\[\]]") then
		strReturn="pwd must contant spec-char"				'密碼必須包含特殊字元
	else
		strReturn="ok 提交過來的數據是" & strPass  '"ok 提交過來的數據是:" & strPass
	end if
	checkPass=strReturn
end function

function regTest(str1,strPattern)
    Set reg = CreateObject("vbscript.regExp")
    reg.Global = True
    reg.IgnoreCase = True
    reg.MultiLine = True
    reg.Pattern = strPattern
    regTest= reg.test(str1)
	set reg=nothing
End function
%>

<p name="check_resualt" id="check_resualt"><%=check_resualt%></p>
</body>
</html>

主要驗證 Function 為 regTest function

 

ref: https://www.twblogs.net/a/5cfe183fbd9eee14029ee02b

感謝前人,感謝 google

=====================================================================================

盡力耍廢也很好

By 金魚