آقایون کد تصویر امنیتی من در ASP.NET اینه:
حالا می خوام بدونم چجوری میتونم رشته ی تولید شده رو اعتبار سنجی بکنم؟؟؟!!!
یعنی از کجا بدونم که رشته درست وارد شده توسط کاربر یا نه؟؟؟
PHP:
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<%@ Import namespace="System.Drawing.Drawing2D" %>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
Dim r as New Random
Dim baseMap As Bitmap = New Bitmap(150, 30)
Dim myGraphic as Graphics = Graphics.FromImage(baseMap)
Dim HBrush As HatchBrush = New HatchBrush( RandomHatch(), GetRandomColor(r))
Dim upBrush as SolidBrush = new SolidBrush(GetRandomColor(r))
Dim fontTitle As Font = New Font("tahoma", 14)
myGraphic.FillRectangle(Brushes.Honeydew, 0, 0, 180, 30)
myGraphic.DrawString(RandomStringGenerator(6), fontTitle, upBrush, r.Next(0, 80), r.Next(0, 10))
Response.ContentType = "image/jpeg"
baseMap.Save(Response.OutputStream, ImageFormat.JPEG)
myGraphic.Dispose()
baseMap.Dispose()
End Sub
Public Function RandomStringGenerator(ByVal intLen As Integer) As String
Dim rRandom As New Random()
Dim Zero As Integer = Asc("0")
Dim Nine As Integer = Asc("9")
Dim capA As Integer = Asc("A")
Dim capZ As Integer = Asc("Z")
Dim litA As Integer = Asc("a")
Dim litZ As Integer = Asc("z")
Dim iRandNum as integer
Dim strTemp as String = ""
Dim i As Integer
While i < intLen
iRandNum = rRandom.Next(Zero, litZ)
If ((((iRandNum > = Zero) And (iRandNum <= Nine) Or _
(iRandNum > = capA) And (iRandNum < = capZ) Or _
(iRandNum > = litA) And (iRandNum < = litZ)))) Then
strTemp = strTemp + Chr(iRandNum)
i+=1
End If
End while
Return strTemp
End Function
Public Function RandomHatch() As HatchStyle
Randomize()
Select Case Rnd() * 56
Case Is < 1 : Return HatchStyle.BackwardDiagonal
Case Is < 2 : Return HatchStyle.Cross
Case Is < 3 : Return HatchStyle.DarkDownwardDiagonal
Case Is < 4 : Return HatchStyle.DarkHorizontal
Case Is < 5 : Return HatchStyle.DarkUpwardDiagonal
Case Is < 6 : Return HatchStyle.DarkVertical
Case Is < 7 : Return HatchStyle.DashedDownwardDiagonal
Case Is < 8 : Return HatchStyle.DashedHorizontal
Case Is < 9 : Return HatchStyle.DashedUpwardDiagonal
Case Is < 10 : Return HatchStyle.DashedVertical
Case Is < 11 : Return HatchStyle.DiagonalBrick
Case Is < 12 : Return HatchStyle.DiagonalCross
Case Is < 13 : Return HatchStyle.Divot
Case Is < 14 : Return HatchStyle.DottedDiamond
Case Is < 15 : Return HatchStyle.ForwardDiagonal
Case Is < 16 : Return HatchStyle.Horizontal
Case Is < 17 : Return HatchStyle.HorizontalBrick
Case Is < 18 : Return HatchStyle.LargeCheckerBoard
Case Is < 19 : Return HatchStyle.LargeConfetti
Case Is < 20 : Return HatchStyle.LargeGrid
Case Is < 21 : Return HatchStyle.LightDownwardDiagonal
Case Is < 22 : Return HatchStyle.LightHorizontal
Case Is < 23 : Return HatchStyle.LightUpwardDiagonal
Case Is < 24 : Return HatchStyle.LightVertical
Case Is < 25 : Return HatchStyle.DottedGrid
Case Is < 26 : Return HatchStyle.Max
Case Is < 27 : Return HatchStyle.Min
Case Is < 28 : Return HatchStyle.NarrowHorizontal
Case Is < 29 : Return HatchStyle.NarrowVertical
Case Is < 30 : Return HatchStyle.OutlinedDiamond
Case Is < 31 : Return HatchStyle.Percent05
Case Is < 32 : Return HatchStyle.Percent10
Case Is < 33 : Return HatchStyle.Percent20
Case Is < 34 : Return HatchStyle.Percent25
Case Is < 35 : Return HatchStyle.Percent30
Case Is < 36 : Return HatchStyle.Percent40
Case Is < 37 : Return HatchStyle.Percent50
Case Is < 38 : Return HatchStyle.Percent60
Case Is < 39 : Return HatchStyle.Percent70
Case Is < 40 : Return HatchStyle.Percent75
Case Is < 41 : Return HatchStyle.Percent80
Case Is < 42 : Return HatchStyle.Percent90
Case Is < 43 : Return HatchStyle.Plaid
Case Is < 44 : Return HatchStyle.Shingle
Case Is < 45 : Return HatchStyle.SmallCheckerBoard
Case Is < 46 : Return HatchStyle.SmallConfetti
Case Is < 47 : Return HatchStyle.SmallGrid
Case Is < 48 : Return HatchStyle.SolidDiamond
Case Is < 49 : Return HatchStyle.Sphere
Case Is < 50 : Return HatchStyle.ZigZag
Case Is < 51 : Return HatchStyle.Trellis
Case Is < 52 : Return HatchStyle.Vertical
Case Is < 53 : Return HatchStyle.Wave
Case Is < 54 : Return HatchStyle.Weave
Case Is < 55 : Return HatchStyle.WideDownwardDiagonal
Case Is < 56 : Return HatchStyle.WideUpwardDiagonal
End Select
End Function
Private Function GetRandomColor(r) As Color
Return Color.FromArgb(r.Next(0, 256), r.Next(0, 256), r.Next(0,256))
End Function
</script>
حالا می خوام بدونم چجوری میتونم رشته ی تولید شده رو اعتبار سنجی بکنم؟؟؟!!!
یعنی از کجا بدونم که رشته درست وارد شده توسط کاربر یا نه؟؟؟