【背景】
近期OA系统要进行安全检查,由于未做密码策略,很多用户仍然使用的是初始化密码,需要在后台批量修改为强密码(数字、小写字母、大写字母、特殊字符的组合),在网上参考了其他平台强密码的生成思路,特编写了Lotusscript下生成强密码的脚本。
【参考代码】
%REM Library createRandomPasswd Created 2014-9-22 by admin/cht Description: Comments for Library %END REM Option Public Option Declare Function fnGetMax(iMin As Integer,iMax As Integer) As Integer On Error GoTo errhandle If iMin>=iMax Then fnGetMax = iMin Else fnGetMax = iMax End If Exit Function errhandle: MsgBox "fnGetMax error:" & Error() & ",erl:" & CStr(Erl()) Exit Function End Function %REM Function fnRandom Description: Comments for Function %END REM Function fnRandom(iMin As Integer,iMax As Integer) As Integer On Error GoTo errhandle fnRandom = CInt(fnGetMax(iMin,Rnd * iMax)) Exit Function errhandle: MsgBox "fnRandom error:" & Error() & ",erl:" & CStr(Erl()) Exit Function End Function %REM sNoPasswd 生成随机密码出错时的初始化密码 iLen 生成随机密码的长度,至少4位 %END REM Function fnRndPasswd(sNoPasswd As String,iLen As Integer) As String On Error GoTo errhandle '初始化密码 'fnRndPasswd = "1qaz!QAZ" fnRndPasswd = sNoPasswd Dim str1(3) As String str1(0) = "abcdefghijklmnopqrstuvwxyz" str1(1) = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" str1(2) = "1234567890" str1(3) = "[email protected]#$%^*_+-';:,." Dim i As Integer Dim iIndex As Integer Dim passwd As String passwd = "" If iLen>4 Then For i=1 To iLen-4 iIndex = fnRandom(0,3) passwd = passwd & Mid(str1(iIndex),fnRandom(1,Len(str1(iIndex))),1) Next End If '为了保障密码必须包含数字、小写字母、大写字母、特殊字符 '后四位直接为小写字母、大写字母、数字、特殊字符 passwd = passwd & Mid(str1(0),fnRandom(1,Len(str1(0))),1) passwd = passwd & Mid(str1(1),fnRandom(1,Len(str1(1))),1) passwd = passwd & Mid(str1(2),fnRandom(1,Len(str1(2))),1) passwd = passwd & Mid(str1(3),fnRandom(1,Len(str1(3))),1) fnRndPasswd = passwd Exit Function errhandle: MsgBox "fnRndPasswd error:" & Error() & ",erl:" & CStr(Erl()) Exit Function End Function
思路并不复杂,LotusScript的随机函数是Rnd(),为了保证密码必须是数字、小写字母、大写字母、特殊字符组合,这段代码里面密码长度至少是4位,并且后面4位分别是:小写字母、大写字母、数字、特殊字符,其实这一块可以随机生成。
时间: 2024-10-10 07:14:37