Questo sito utilizza cookies, anche di terze parti, per mostrare pubblicità e servizi in linea con il tuo account. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Mysql - Login md5
Forum - C# / VB.NET - Mysql - Login md5

Avatar
Aiizen (Normal User)
Newbie


Messaggi: 1
Iscritto: 05/06/2013

Segnala al moderatore
Postato alle 13:35
Mercoledì, 05/06/2013
Salve ragazzi
Non riesco a creare un login md5 mysql potete aiutarmi?

Codice sorgente - presumibilmente VB.NET

  1. Imports System.Security.Cryptography
  2. Imports MySql.Data.MySqlClient
  3. Public Class Form1
  4.  
  5.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  6.        Dim conn As MySqlConnection
  7.         conn = New MySqlConnection
  8.         conn.ConnectionString = "server=localhost;" & "user id=root;" & "password=12345;" & "database=protezione"  'Server data
  9.  
  10.         Try
  11.             conn.Open() ' open the connection
  12.         Catch myerror As MySqlException
  13.             MsgBox("Impossibile connettersi al database: " & myerror.Message.ToString) ' catch the error
  14.         End Try
  15.  
  16.         Dim user As String = txtID.Text
  17.         Dim pass As String = MD5StringHash(txtPW.Text)
  18.  
  19.         Dim myAdapter As New MySqlDataAdapter
  20.         Dim SQLQuery As String = "SELECT * FROM user WHERE Username='" + Replace(user, "", "") + "' AND Password='" + Replace(pass, "", "") & "'" ' Das ist die Abfrage welche Prüft ob der Account existiert.Die txt_benutzer ist die Textbox in der der Benutzername eingeben wird und txt_passwort bekommt das Passwort
  21.         Dim myCommand As New MySqlCommand
  22.         myCommand.Connection = conn
  23.         myCommand.CommandText = SQLQuery
  24.  
  25.         myAdapter.SelectCommand = myCommand
  26.         Dim myData As MySqlDataReader
  27.         myData = myCommand.ExecuteReader() ' start query
  28.         If myData.HasRows Then ' if the pw/id is correct
  29.             MsgBox("Accesso Consentito.")
  30.             conn.Close()
  31.             conn.Open()
  32.  
  33.         Else 'Display error
  34.             MsgBox("Accesso Negato")
  35.         End If
  36.  
  37.     End Sub
  38.  
  39. End Class




Il modulo:
Codice sorgente - presumibilmente VB.NET

  1. Imports System.Security.Cryptography
  2. Imports System.Text
  3. Module md5
  4.  
  5.     Public Function MD5StringHash(ByVal strString As String) As String
  6.         Dim MD5 As New MD5CryptoServiceProvider
  7.         Dim Data As Byte()
  8.         Dim Result As Byte()
  9.         Dim Res As String = ""
  10.         Dim Tmp As String = ""
  11.  
  12.         Data = Encoding.ASCII.GetBytes(strString)
  13.         Result = MD5.ComputeHash(Data)
  14.         For i As Integer = 0 To Result.Length - 1
  15.             Tmp = Hex(Result(i))
  16.             If Len(Tmp) = 1 Then Tmp = "0" & Tmp
  17.             Res += Tmp
  18.         Next
  19.         Return Res
  20.     End Function
  21.  
  22. End Module



In rete tutti usano questo codice.. ma quando inserisco la pass mi dice accesso negato.
Grazie in anticipo

PM Quote