What’s Going On?

Got some emails asking what’s been going on. I know I haven’t posted in a while. Some people miss my daily code snippets and short tutorials. I’ve been working hard on an anti-cheat system for BHD with http://cheatsense.com

I haven’t completly neglected the site. I’ll post some code tutorials tonight on a few more hashing techniques and string encryption. I will also be posting soon a tutorial on how to control a forms events and controls from within a different class. Unlike VB.NET, C# does not automatically inherit the forms methods and control methods.

I’ll also talk about obfuscation and .Net application security, secure string and anti-debugging methods.

Popularity: unranked [?]

.NET Gravatar Library

I’ve updated my Gravatar source. I am no longer working on the control version. I have focused my attention to a library model. With the library you are able to manipulate the image more then you could with the control. The image is stored in memory as passed as an image. I am working on arrays that will allow you to pass an overload containing a list of emails and return the Gravatar in the given order.

You can find out more here!

Popularity: unranked [?]

Captcha .NET

I was searching Google and found no results for a Captcha control for Windows development. So I thought I’d create one for .NET

Features:

  • Case Sensitive Characters
  • Change Background/Foreground Color
  • Change Font/Font Size
  • Verify Captcha Easily

Example Source:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Captcha1.CreateCaptcha()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

If Captcha1.VerifyCaptcha(TextBox1.Text) = True Then

MsgBox("OK")

Else

MsgBox("BAD")

End If

End Sub

http://lifeofajackass.com/wp-content/plugins/downloads-manager/img/icons/default.gif download: Captcha.NET (6.61KB)
added: 29/03/2009
clicks: 1326
description: Captcha.NET is a control to incorporate Captcha image verification into your .NET applications.

captcha Captcha .NET

Popularity: unranked [?]

Gravatar & .NET

Some emails coming in wanting to know an easy way to get Gravatars into their .NET applications. I’ll show 2 ways, both in C# and VB.

First I’ll share with you my MD5 function used to return the hash of a string. In this case, the hash of a users email address.

Function MD5(ByVal strToHash As String) As String
Dim md5Obj As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim bytesToHash() As Byte = System.Text.Encoding.ASCII.GetBytes(strToHash)

bytesToHash = md5Obj.ComputeHash(bytesToHash)

Dim strResult As String = ""

For Each b As Byte In bytesToHash
strResult += b.ToString("x2")
Next

Return strResult
End Function

Create a new windows forms application and add a single picturebox control. For test/example purpose, please the following code in your “Form1_Load” sub.

'Declare a constant here that is half of our URL
Const GURL = "http://www.gravatar.com/avatar/"

'GravatarSize ranges from 1-512
'Rating ranged from G, PG, R, X
'IconType ranges from monsterid, identicon, wavatar
Dim tmp As String = GURL & MD5(Email) & "?s=" & GravatarSize & "&r=" & Rating & "&d=" & IconType

'Now lets use the picturebox "ImageLocation" method to load the Image.
picGravatar.ImageLocation = tmp

An example would be:

Dim tmp As String = GURL & MD5(dremation@gmail.com) & "?s=60&r=g&d=monsterid"

The result would be
Gravatar

 

Now, for the C# example. Although C# and VB are very close in syntext I will include this example as well.
First, here is the MD5 function.

 private string  MD5(string Email)
{
System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(Email);
data = x.ComputeHash(data);
string ret = "";
for (int i = 0; i < data.Length; i++)
ret += data[i].ToString("x2").ToLower();
return ret;
}

And now let’s get the Gravatar and show it in the picturebox.

 const string GURL = "http://www.gravatar.com/avatar/";

string tmp = GURL + MD5("dremation@gmail.com") + "?s=60&r=g&d=monsterid";
picGravatar.ImageLocation = tmp;

And there you have C# and VB .NET examples on how to retrieve a Gravatar using a users email address. This is nice because using this method is fast and simple.

Popularity: unranked [?]

TimesURL & .NET

I’ve got a few emails regarding http://timesurl.at. If you want to use this service you can still the use code from [TinyURL & .NET]. All you have to do is change one line of code.

Change

http://tinyurl.com/api-create.php?url=

to

http://timesurl.at/api/rest.php?url=

And there you have it. This also works with most other URL shortener sites. If not, just email me and I”ll write up some code for the site you need.

Popularity: unranked [?]

TinyURL & .NET

Ever want to parse a TinyURL in your .NET application? TinyURL has a very simple and easy to use API. I’ll guide you through the process of returning a TinyURL in VB.NET 2008 and C# .NET 2008

First off you want to create a function that returns a string.
Simple enough, this function ask for the parameter of URL and will return a string. 

Public Function GetTinyUrl(ByVal URL As String) As String
End Function

Next you want to make sure you’re not using the TinyURL service for no reason. The API is designed for links over 30 characters long. So if you have a 20 character URL TinyURL will end up giving you a 20-35 character URL. So let’s check this first. We’re going to use the Try/Catch method incase something might go wrong. If so, we’ll return the users URL back to him.

Try
    If Url.Length <= 30 Then
       Return URL
     End If
Catch
       Return Url
     End Try

Next we are going to check our link to make sure it starts with “http”.

If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
  Url = "http://" + Url
End If

Now that we have that done, lets declare some variables. “req” is used to create  our request to use the API, “rsp” is used to get the response from our request. Simple enough, right? “txt” is used to store our ending result from our Stream Reader.

Dim req As WebRequest = WebRequest.Create("http://tinyurl.com/api-create.php?url=" + Url)
Dim rsp As WebResponse = req.GetResponse()
Dim txt As String

Now lets actually read our request and store the result in our txt variable. Also, let’s go ahead and Return our result to the user.

Using rdr As StreamReader = New StreamReader(rsp.GetResponseStream())
          txt = rdr.ReadToEnd()
End Using
Return txt

Now, let’s put it all together and we have this. Pass the URL parameter and recieve the TinyURL in return.

    Public Function GetTinyUrl(ByVal URL As String) As String
        Try
            If Url.Length <= 30 Then
                Return URL
            End If
            If Not Url.ToLower().StartsWith("http") AndAlso Not Url.ToLower().StartsWith("ftp") Then
                Url = "http://" + Url
            End If
            Dim req As WebRequest = WebRequest.Create("http://tinyurl.com/api-create.php?url=" + Url)
            Dim rsp As WebResponse = req.GetResponse()
            Dim txt As String
            Using rdr As StreamReader = New StreamReader(rsp.GetResponseStream())
                txt = rdr.ReadToEnd()
            End Using
            Return txt
        Catch
            Return Url
        End Try
    End Function

I hope this helps you out, and don’t forget to comment!

Popularity: unranked [?]

GravatarGet: Update

I’ve updated my user control for Gravatar. Version now is, 1.2.4.0. I’ve adds support for a caption bar to shows the users email address along with the avatar. I’ve added 4 new properties that allow you to control the size, rating, email and caption. I have plans to add support for frames/borders, info overlays, captions on the left, right, top of avatar, mouse over effects and more.

Check out the new version here!

Popularity: unranked [?]

Gravatar .NET Control

UPDATE AND PAGE HERE

I’m working on a .NET Gravatar control. A user will be able to retrieve the given emails avatar, or fallback to a default avatar provided by Gravatar.  The developer will be able to control the [size],[rating],[fallback image]. 

Why? That’s easy! Maybe you are developing an application that involves chat, email, p2p activities or something like that. Isn’t it nice to show your picture? I’m sure there are other applications for this type of user control.

        GravatarGet1.Email = "dremation@gmail.com"
        GravatarGet1.ShowGravatar(60, "g", "identicon")

The parameters, (60, g, identicon) are the parameters Gravatar allows to be passed.

Size:  Any number from 1 to 512 
Rating: G, PG, R, X
Default: identicon, monsterid, wavatar

test1 Gravatar .NET Control

In the next release I plan on easy methods of defining the parameters. I will also include image ttiels, information titles and context menu support.

Please leave comments for errors, suggestions, ideas and bugs.  

download button Gravatar .NET Control

Popularity: unranked [?]

MySQL & .NET

While coding up an application I’ve been working on I thought about incorporating MySQL to track usage, users and registrations. However, I realized I didn’t know the first thing about MySQL. Of course I use Wordpress, but thats just upload, click, install! So here I am with a complete clientside registration, user and tracking system and no idea how to send it to my MySQL database! So anyway, I’ve decided to brush up on MySQL and using it with .NET. I plan on releasing a few tutorials to simplify the use and help the beginners out there.

Popularity: 1% [?]