mysql - 将我的 MySQL 密码加密为来自 VB.net 的 MD5 哈希时遇到问题

标签 mysql vb.net encryption hash

我正在尝试将用户输入到我的数据库的密码哈希为 MD5,但我遇到了问题。我知道 MD5 不像以前那么安全,现在不加盐,这只是为了测试目的,我实际上不会部署它供人们使用。这只是为了好玩!用户名被输入到数据库中,但密码没有被输入到数据库中。这是我的代码:

Imports MySql.Data.MySqlClient
Imports System.Security.Cryptography
Imports System.Text


Public Class frmSignup
Dim ServerString As String = "Server=localhost;User        Id=root;Password=;Database=accountinfo"
Dim SQLConnection As MySqlConnection = New MySqlConnection

Private Sub Form3_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    SQLConnection.ConnectionString = ServerString

    Try
        If SQLConnection.State = ConnectionState.Closed Then
            SQLConnection.Open()
            MsgBox("Successfully connected to DB")

        Else
            SQLConnection.Close()
            MsgBox("Failed to connect to DB")
        End If
    Catch ex As Exception
        MsgBox(ex.ToString)

    End Try
End Sub

Public Sub SaveAccountInformation(ByRef SQLStatement As String)
    Dim cmd As MySqlCommand = New MySqlCommand

    With cmd
        .CommandText = SQLStatement
        .CommandType = CommandType.Text
        .Connection = SQLConnection
        .ExecuteNonQuery()
    End With
    SQLConnection.Close()
    SQLConnection.Dispose()
End Sub

Private Sub btnSignup_Click(sender As Object, e As EventArgs) Handles btnSignup.Click
    If txtPasswd.Text = txtPasswd2.Text Then
        MessageBox.Show("Passwords Match!")

        Dim HashedPass As String = ""

        'Converts the Password into bytes, computes the hash of those bytes, and then converts them into a Base64 string

        Using MD5hash As MD5 = MD5.Create()

            System.Convert.ToBase64String(MD5hash.ComputeHash(System.Text.Encoding.ASCII.GetBytes(txtPasswd.Text)))

        End Using


        Dim SQLStatement As String = "INSERT INTO accountinfodb(`Usernames`, `Passwords`) VALUES ('" & txtUsername.Text & "','" & HashedPass & "')"
        SaveAccountInformation(SQLStatement)



        MessageBox.Show("Account Successfully Registered")
        frmLogin.Show()
        frmLoginScreen.Hide()
    Else
        MessageBox.Show("Passwords Do Not Match!")
        txtPasswd.Text = Focus()
        txtPasswd.Clear()
        txtPasswd2.Text = Focus()
        txtPasswd2.Clear()

    End If
End Sub
End Class

我认为我可能在 SQL 查询中添加了错误的值,但如果我添加 txtPasswd,我不确定将 HashedPass 变量放入代码中的位置?

最佳答案

您的问题的答案可以在此处使用基本相同的代码找到:

VB.NET login with a MySQL database

直接回答链接:

https://stackoverflow.com/a/22939770/1475285

关于mysql - 将我的 MySQL 密码加密为来自 VB.net 的 MD5 哈希时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34866335/

相关文章:

php - 如何在 PHP 中使用 multi_query 制作准备好的语句

c# - 通过鼠标单击获取图表上的 x 坐标

java - C#.net 到 Java-使用带密码的 AES 加密和解密

php - 使用 PHP 的 TRIPLE DES 加密/解密

php - 使用 PHP、JSON 并在 HTML 上显示的 MySQL 查询

mysql - 连接池到底是如何工作的?

c# - 获取特定 linq to sql 表的名称

正则表达式 - 返回引号之间的所有字符,每行多次

java - 如何使用充气城堡解密 pkcs8 加密私钥?

java - 'readingid' 中的未知列 'where clause'