PDA

View Full Version : آموزش: تبدیل پسور کاربر به متن امن برای ذخیره در دیتابیس



ROSTAM2
دوشنبه 13 شهریور 1402, 09:20 صبح
با سلام به همه
امیدوارم که این کد براتون کارآمد باشه و ازش استفاده کنید:
154902


Imports System.Text
Imports System.Security.Cryptography
Public Class Form1
Function GetMd5Hash(ByVal input As String) As String
' Create a new instance of the MD5 object.
Dim md5Hasher As MD5 = MD5.Create()
' Convert the input string to a byte array and compute the hash.
Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(in put))
' Create a new Stringbuilder to collect the bytes
' and create a string.
Dim sBuilder As New StringBuilder()
' Loop through each byte of the hashed data
' and format each one as a hexadecimal string.
Dim i As Integer
For i = 0 To data.Length - 1
sBuilder.Append(data(i).ToString("x2"))
Next i
' Return the hexadecimal string.
Return sBuilder.ToString()
End Function
' Verify a hash against a string.
Function verifyMd5Hash(ByVal input As String, ByVal hash As String) As Boolean
' Hash the input.
Dim hashOfInput As String = getMd5Hash(input)
' Create a StringComparer an compare the hashes.
Dim comparer As StringComparer = StringComparer.OrdinalIgnoreCase
If 0 = comparer.Compare(hashOfInput, hash) Then
Return True
Else
Return False
End If
End Function
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Me.Label1.Text = GetMd5Hash(Me.TextBox1.Text)
End Sub


Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim b As Boolean = verifyMd5Hash(Me.TextBox1.Text, Me.Label1.Text)
MsgBox(If(b, "Correct Password", "Incorrect Password!"))
End Sub
End Class


https://www.aparat.com/v/8hNL4
(https://www.aparat.com/v/8hNL4)در ضمن خوشحال می شم کانال آپارات من رو دنبال کنید: آپارات - سرویس اشتراک ویدیو (aparat.com) (https://www.aparat.com/vbloverprogrammer/)

دانلود سورس پروژه :