U prošlom postu smo imali generator jedinstvenog ključa napisan u PHP-u. Sada imamo sličan generator jedinstvenog ključa napisan za ASP/ASP.NET. Kod izgleda ovako:
<script language="VB" runat="Server">
Function Random_Kod(Optional ByVal Broj As Integer = 10, Optional ByVal Karakteri As String = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") As String
Dim i As Integer
Dim s As String
Dim Duzina As Integer
Dim b As Integer
Randomize
If Broj < 1 Then Broj = 1
If Broj > 32 Then Broj = 32
Duzina = Len(Karakteri)
s = ""
For i = 1 To Broj
b = Int(1 + Duzina * Rnd)
s = s & Mid(Karakteri, b, 1)
Next
Random_Kod = s
End Function
</script>
Funkciji možemo da prosledimo nijedan, jedan ili 2 parametra:
<%
Response.Write (Random_Kod() & "<br>")
Response.Write (Random_Kod(5) & "<br>")
Response.Write (Random_Kod(20) & "<br>")
Response.Write (Random_Kod(8, "01") & "<br>")
Response.Write (Random_Kod("1234") & "<br>")
Response.Write (Random_Kod(20, "0123456789ABCDEF") & "<br>")
%>
na stranici dobijamo:
Wpbua6piwU
Tn4iI
KV1QeNGddSyvSrmN7H3z
10011101
0dk5Knekg06pfOGlF983R1mWx9SW63Dt
D41F5B06725ED9792CB9
Napomena:
U ASP.NET-u funkcije i procedure se pišu unutar tagova: <script language="VB" runat="Server"></script>, dok se u ASP-u pišu nutar standardnih ASP tagova: <% i %>.
Pozivanje funkcija i procedura u ASP/ASP.NET, kao i ostali programski kod na stranici se piše unutar tagova <% i %>.
Ceo kod (npr: index.aspx) stranice bi izgledao ovako:
<script language="VB" runat="Server">
Function Random_Kod(Optional ByVal Broj As Integer = 10, Optional ByVal Karakteri As String = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") As String
Dim i As Integer
Dim s As String
Dim Duzina As Integer
Dim b As Integer
Randomize
If Broj < 1 Then Broj = 1
If Broj > 32 Then Broj = 32
Duzina = Len(Karakteri)
s = ""
For i = 1 To Broj
b = Int(1 + Duzina * Rnd)
s = s & Mid(Karakteri, b, 1)
Next
Random_Kod = s
End Function
</script>
<html>
<head>
<title> Gererator jedinstvenog ključa </title>
</head>
<body>
<%
Response.Write (Random_Kod() & "<br>")
Response.Write (Random_Kod(5) & "<br>")
Response.Write (Random_Kod(20) & "<br>")
Response.Write (Random_Kod(8, "01") & "<br>")
Response.Write (Random_Kod("1234") & "<br>")
Response.Write (Random_Kod(20, "0123456789ABCDEF") & "<br>")
%>
</body>
</html>
<script language="VB" runat="Server">
Function Random_Kod(Optional ByVal Broj As Integer = 10, Optional ByVal Karakteri As String = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") As String
Dim i As Integer
Dim s As String
Dim Duzina As Integer
Dim b As Integer
Randomize
If Broj < 1 Then Broj = 1
If Broj > 32 Then Broj = 32
Duzina = Len(Karakteri)
s = ""
For i = 1 To Broj
b = Int(1 + Duzina * Rnd)
s = s & Mid(Karakteri, b, 1)
Next
Random_Kod = s
End Function
</script>
Funkciji možemo da prosledimo nijedan, jedan ili 2 parametra:
- Random_Kod ()
- Random_Kod(dužina ključa)
- Random_Kod(dužina ključa, dozvoljeni karakteri)
<%
Response.Write (Random_Kod() & "<br>")
Response.Write (Random_Kod(5) & "<br>")
Response.Write (Random_Kod(20) & "<br>")
Response.Write (Random_Kod(8, "01") & "<br>")
Response.Write (Random_Kod("1234") & "<br>")
Response.Write (Random_Kod(20, "0123456789ABCDEF") & "<br>")
%>
na stranici dobijamo:
Wpbua6piwU
Tn4iI
KV1QeNGddSyvSrmN7H3z
10011101
0dk5Knekg06pfOGlF983R1mWx9SW63Dt
D41F5B06725ED9792CB9
Napomena:
U ASP.NET-u funkcije i procedure se pišu unutar tagova: <script language="VB" runat="Server"></script>, dok se u ASP-u pišu nutar standardnih ASP tagova: <% i %>.
Pozivanje funkcija i procedura u ASP/ASP.NET, kao i ostali programski kod na stranici se piše unutar tagova <% i %>.
Ceo kod (npr: index.aspx) stranice bi izgledao ovako:
<script language="VB" runat="Server">
Function Random_Kod(Optional ByVal Broj As Integer = 10, Optional ByVal Karakteri As String = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") As String
Dim i As Integer
Dim s As String
Dim Duzina As Integer
Dim b As Integer
Randomize
If Broj < 1 Then Broj = 1
If Broj > 32 Then Broj = 32
Duzina = Len(Karakteri)
s = ""
For i = 1 To Broj
b = Int(1 + Duzina * Rnd)
s = s & Mid(Karakteri, b, 1)
Next
Random_Kod = s
End Function
</script>
<html>
<head>
<title> Gererator jedinstvenog ključa </title>
</head>
<body>
<%
Response.Write (Random_Kod() & "<br>")
Response.Write (Random_Kod(5) & "<br>")
Response.Write (Random_Kod(20) & "<br>")
Response.Write (Random_Kod(8, "01") & "<br>")
Response.Write (Random_Kod("1234") & "<br>")
Response.Write (Random_Kod(20, "0123456789ABCDEF") & "<br>")
%>
</body>
</html>