RE: .Net Coding Challenge #5 - BaussHacker - 05-11-2011
Most peoples will just generate lables, which will make me laugh a bit, because you can easy crack them. They won't protect anything really.
RE: .Net Coding Challenge #5 - iCrack - 05-11-2011
(05-11-2011, 06:22 AM)BaussHacker Wrote: Most peoples will just generate lables, which will make me laugh a bit, because you can easy crack them. They won't protect anything really.
Which I actually did...
You probably right ...
RE: .Net Coding Challenge #5 - cOld fus1on - 05-11-2011
I'm at work work right now
But when I get home, I'll do this..., prolly be in cSharp tho...
RE: .Net Coding Challenge #5 - KoBE - 05-11-2011
This could very easily be expanded on to make a decent Captcha verifier class. I whipped this up before bed so I didn't put any effort into a GUI. I mainly wanted to show a different way to do this rather then generating a Label.
Enjoy.
Code: Imports System.Drawing
Imports System.Security.Cryptography
Public Class Form1
Dim x As String 'used to store the text before painting, then stores the MD5 of what was painted
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
'new bitmap to draw the captcha
Dim xBitmap As New Bitmap(200, 50)
'new brush to paint with
Dim xBrush As New SolidBrush(Color.Black)
'font used to draw captcha
Dim xFont As New Font(FontFamily.GenericSansSerif, 20)
'create a new graphic from the bitmat we created
Dim gfx As Graphics = Graphics.FromImage(xBitmap)
'return an 8 character string
x = NewRand()
'draw our string to the graphic
gfx.DrawString(x, xFont, xBrush, 0, 0)
'set the picture box image to our captcha
pbCap.Image = xBitmap
'md5 our captcha so incase stolen(via windows handle)
x = TxtHash(x)
End Sub
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
'hash the answer and verify against the hashed captcha
If TxtHash(txtAnswer.Text) = x Then
MessageBox.Show("Sweet balls you got it!")
Else
MessageBox.Show("Uh oh, you suck.")
End If
End Sub
Private Function NewRand()
'characters allowed in the captcha
Dim strText As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
'new random number generator()
Dim rand As New Random
'holds our random character string
Dim xString As String = ""
For i As Integer = 0 To 8
'loops 8 times, getting a random character from our allowed characters
xString += strText.Substring(rand.Next(strText.Length - 1), 1)
Next
'return the result
Return xString
End Function
Private Function TxtHash(ByVal str As String)
'new md5 class
Dim hash As MD5 = MD5.Create()
'md5 hash in byte form
Dim bytes As Byte() = hash.ComputeHash(System.Text.Encoding.ASCII.GetBytes(str))
'return the md5 as a string
Return BitConverter.ToString(bytes).Replace("-", "")
End Function
End Class
RE: .Net Coding Challenge #5 - iCrack - 05-12-2011
(05-11-2011, 10:18 PM)KoBE Wrote:
This could very easily be expanded on to make a decent Captcha verifier class. I whipped this up before bed so I didn't put any effort into a GUI. I mainly wanted to show a different way to do this rather then generating a Label.
Enjoy.
Code: Imports System.Drawing
Imports System.Security.Cryptography
Public Class Form1
Dim x As String 'used to store the text before painting, then stores the MD5 of what was painted
Private Sub btnGenerate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGenerate.Click
'new bitmap to draw the captcha
Dim xBitmap As New Bitmap(200, 50)
'new brush to paint with
Dim xBrush As New SolidBrush(Color.Black)
'font used to draw captcha
Dim xFont As New Font(FontFamily.GenericSansSerif, 20)
'create a new graphic from the bitmat we created
Dim gfx As Graphics = Graphics.FromImage(xBitmap)
'return an 8 character string
x = NewRand()
'draw our string to the graphic
gfx.DrawString(x, xFont, xBrush, 0, 0)
'set the picture box image to our captcha
pbCap.Image = xBitmap
'md5 our captcha so incase stolen(via windows handle)
x = TxtHash(x)
End Sub
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
'hash the answer and verify against the hashed captcha
If TxtHash(txtAnswer.Text) = x Then
MessageBox.Show("Sweet balls you got it!")
Else
MessageBox.Show("Uh oh, you suck.")
End If
End Sub
Private Function NewRand()
'characters allowed in the captcha
Dim strText As String = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
'new random number generator()
Dim rand As New Random
'holds our random character string
Dim xString As String = ""
For i As Integer = 0 To 8
'loops 8 times, getting a random character from our allowed characters
xString += strText.Substring(rand.Next(strText.Length - 1), 1)
Next
'return the result
Return xString
End Function
Private Function TxtHash(ByVal str As String)
'new md5 class
Dim hash As MD5 = MD5.Create()
'md5 hash in byte form
Dim bytes As Byte() = hash.ComputeHash(System.Text.Encoding.ASCII.GetBytes(str))
'return the md5 as a string
Return BitConverter.ToString(bytes).Replace("-", "")
End Function
End Class
Pretty nice man!
Well done!
RE: .Net Coding Challenge #5 - Modestep - 05-12-2011
I made this in like 10 mins, i dont have mutch time
Code: Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cola As String = Random()
Label1.Text = cola
End Sub
Public Function Random() As String
Random = ""
Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
Const strNumbers As String = "1234567890"
Dim strTotal As String
Dim i As Short
strTotal = strUpper & strLower & strNumbers
For i = 1 To CInt("8")
Random = Random & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
Next i
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = Label1.Text Then
MessageBox.Show("You may crap stones now")
Else
Me.Close()
End If
End Sub
End Class
RE: .Net Coding Challenge #5 - iCrack - 05-12-2011
(05-12-2011, 01:45 PM)dudesons123 Wrote: I made this in like 10 mins, i dont have mutch time
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cola As String = Random()
Label1.Text = cola
End Sub
Public Function Random() As String
Random = ""
Const strUpper As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Const strLower As String = "abcdefghijklmnopqrstuvwxyz"
Const strNumbers As String = "1234567890"
Dim strTotal As String
Dim i As Short
strTotal = strUpper & strLower & strNumbers
For i = 1 To CInt("8")
Random = Random & Mid(strTotal, Int((Rnd() * Len(strTotal)) + 1), 1)
Next i
End Function
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = Label1.Text Then
MessageBox.Show("You may crap stones now")
Else
Me.Close()
End If
End Sub
End Class
http://i.min.us/in25DI.PNG
I think you may work a bit in the GUI ...
Use Code and Image tags instead tho...
RE: .Net Coding Challenge #5 - モrainee - 05-14-2011
It looks great mate!
Vwry nice .I like it
RE: .Net Coding Challenge #5 - thanasis2028 - 05-21-2011
Ok here is my submission:
I used the RichTextBox and made some rtf encoding to achieve this
Code: Public Class Form1
Private r As New Random()
Private Function GetRandomRTF(ByVal Length As Byte) As String
Dim Chars As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
Dim Str As String = ""
Dim FinalStr As String = ""
For i As Byte = 1 To Length
Str = Chars.Chars(r.Next(Chars.Length - 1))
Select Case r.Next(5) 'Colors
Case 0
Str = "\cf1 " + Str
Case 1
Str = "\cf2 " + Str
Case 2
Str = "\cf3 " + Str
Case 3
Str = "\cf4 " + Str
Case 4
Str = "\cf5 " + Str
End Select
Select Case r.Next(7) 'Bold/Italic/Underline
Case 0
Str = "{\b " + Str + "}"
Case 1
Str = "{\i " + Str + "}"
Case 2
Str = "{\ul " + Str + "}"
Case 3
Str = "{\b {\i " + Str + "}}"
Case 4
Str = "{\b {\ul " + Str + "}}"
Case 5
Str = "{\i {\ul " + Str + "}}"
End Select
FinalStr += Str
Next
Return FinalStr
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.BackColor = Color.FromArgb(103, 153, 52)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RichTextBox1.Clear()
TextBox1.Clear()
RichTextBox1.Text = "initialtext"
RichTextBox1.Rtf = Replace(RichTextBox1.Rtf, "initialtext", "{\colortbl;\red0\green0\blue0;\red255\green0\blue0;\red0\green255\blue0;\red0\green0\blue255;\red255\green0\blue255;}" + GetRandomRTF(r.Next(6, 11)))
Button2.Enabled = True
TextBox1.Select()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox1.Text = RichTextBox1.Text Then
MsgBox("You got it right! You are not a machine!", , "Access Granted!")
Else
MsgBox("Machines get no access to the system!", , "Access Denied!")
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown
If e.KeyCode = Keys.Enter Then Button2_Click(Me, EventArgs.Empty)
End Sub
End Class
Download .exe
Download full source
|