ValidationCode Function:
Generate a random code of defined length.
Description:
ValidationCode Function generates a random code or password of defined length. Call it like this to generate a 10 letter long CODE: Response.Write "Your CODE: " & ValidationCode( 10, "" ) Or if you want to just use certain characters: Response.Write "Your CODE: " & ValidationCode( 5, "ABCabc" ) This will generate a random code only using the 'characters ABCabc, therefore it give might result like: Your CODE: CabCB
Syntax:
ValidationCode( nNoChars, sValidChars )
Details:
'--- nNoChars = length of generated password '--- sValidChars = valid characters. If zerolength-string ( "" ) then '--- default is used: A-Z AND a-z AND 0-9
Example:
<%
response.write ValidationCode(10, "") '--- returns: C15xTyrIId
%>
ASP Source Code:
<%
Public Function ValidationCode( nNoChars, sValidChars ) '--- nNoChars = length of generated password '--- sValidChars = valid characters. If zerolength-string ( "" ) then '--- default is used: A-Z AND a-z AND 0-9 Const szDefault = "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ0123456789" Dim nCount Dim sRet Dim nNumber Dim nLength Randomize '--- init random If sValidChars = "" Then sValidChars = szDefault End If nLength = Len( sValidChars ) For nCount = 1 To nNoChars nNumber = Int((nLength * Rnd) + 1) sRet = sRet & Mid( sValidChars, nNumber, 1 ) Next ValidationCode = sRet End Function
%>
|