Tuesday, September 28, 2010

Generate A Random Number

Dim rannum As Random
        Dim number As Integer
        rannum = New Random
        number = rannum.Next(1, 1001)
        TextBox1.Text = number.ToString


The 1 is the lowest number it will generate.
The 1001 is the highest number it will generate.

Change TextBox1.Text into the control you want the number to show.
It could be a label or button.

MD5 Encryption For Your Project

Hi, This is my first tutorial so I hope no one flames me :[
I'll be showing you guys how to add an MD5 Encryption into your project so for those people who use this as a password :
if textbox1.text = "password" then
bla bla

people can easily get your password :P

So to start out you put this at the top most of your form ( any )


Imports System.Security.Cryptography
Imports System.IO

Then put this right under your Public Class Form


Public oFile As System.IO.File
    Public password As String = "MD5 HASH HERE"  'md5 hash of your password
    Public enteredpassword As String
    Public s As Stream

Now add this function, right under the above code


Function getMD5Hash(ByVal strToHash As String) As String
        Dim md5Obj As New 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

Now you need to go on google and search for an MD5 encryptor
get the hash and replace the red with your MD5

So here's how you use it

let's say you have a Textbox and a button
the button check to see if the password is correct in textbox1
this is what you would do

enteredpassword = getMD5Hash(Textbox1.Text)
If enteredpassword = password Then
something happens if the password is correct
Else
Something happen when the password is wrong
End If

Thanks for coming :]

VB CODES

I will be posting VB Codes like snippets, source codes, and some tutorials here so be sure to  check back here from time to time.