Sunday, June 15, 2014

VB.Net: Encrypt Password.

If you are developing a password-protected web site or database, then are you sure about storing user password information securely?

Realize that the data in your database is not safe. So you could encrypt the data that you think it's important. Here is an algorithm by using MD5 to encrypt the text you have fielded.
Below is a sample code how to use MD5.
Imports System.Security.Cryptography
Imports System.Text
Public Class Form1
    Dim md5CSP As New MD5CryptoServiceProvider()
    Dim textToEncrypt As Byte()

    Dim encoder As New UTF8Encoding()
    Sub Encrypter()
        textToEncrypt = md5CSP.ComputeHash(encoder.GetBytes(TextBox1.Text))
        TextBox2.Text = Convert.ToBase64String(textToEncrypt)
        TextBox2.Enabled = True
    End Sub

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