Mysql Login Form

  • C#

Es gibt 7 Antworten in diesem Thema. Der letzte Beitrag () ist von Gelöschter Benutzer.

    Mit einem PHP-Skript, das die entsprechenden Daten in der MySQL-Datenbank abfrägt.
    Hab dir eben ein kleines Skript geschrieben, das du einfach auf deinen Webserver laden und im Programm aufrufen kannst.

    PHP-Quellcode

    1. /* Benötigt:
    2. * MySQL-Tabelle mit den Spalten 'user' für den Benutzernamen und 'pass' für den md5-Hash des Passworts.
    3. */
    4. $user = 'deinUsername';
    5. $pass = 'deinPasswort';
    6. $db = 'deineDatenbank';
    7. $host = 'deinHost';
    8. $table = 'users';
    9. $con = mysql_connect($host, $user, $pass);
    10. mysql_select_db($db, $con);
    11. $u = mysql_real_escape_string($_GET['u'], $con);
    12. $p = md5($_GET['p']);
    13. $query = "SELECT * FROM $table WHERE (user='$u') AND (pass='$p')";
    14. $result = mysql_query($query, $con);
    15. echo (mysql_num_rows($result) > 0 ? '1' : '0');

    In deinem Programm könnte das dann so aussehen:

    VB.NET-Quellcode

    1. ' Quelle: http://www.a1vbcode.com/vbtip-149.asp
    2. Private Function GenerateHash(ByVal SourceText As String) As String
    3. 'Create an encoding object to ensure the encoding standard for the source text
    4. Dim Ue As New UnicodeEncoding()
    5. 'Retrieve a byte array based on the source text
    6. Dim ByteSourceText() As Byte = Ue.GetBytes(SourceTStext)
    7. 'Instantiate an MD5 Provider object
    8. Dim Md5 As New MD5CryptoServiceProvider()
    9. 'Compute the hash value from the source
    10. Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
    11. 'And convert it to String format for return
    12. Return Convert.ToBase64String(ByteHash)
    13. End Function
    14. Dim user = "blah", pass = GenerateHash("dasPasswort")
    15. Using client As New System.Net.WebClient()
    16. Dim url = String.Format("http://deineDomain.de/skript.php?u={0}&p={0}", user, pass)
    17. Dim response = client.DownloadString(New Uri(url))
    18. If response = "1" Then
    19. ' erfolgreich
    20. Else
    21. ' nicht erfolgreich
    22. End If
    23. End Using


    Ungetestet, sollte aber funktionieren.

    haiyyu schrieb:

    Mit einem PHP-Skript, das die entsprechenden Daten in der MySQL-Datenbank abfrägt.
    Hab dir eben ein kleines Skript geschrieben, das du einfach auf deinen Webserver laden und im Programm aufrufen kannst.

    PHP-Quellcode

    1. /* Benötigt:
    2. * MySQL-Tabelle mit den Spalten 'user' für den Benutzernamen und 'pass' für den md5-Hash des Passworts.
    3. */
    4. $user = 'deinUsername';
    5. $pass = 'deinPasswort';
    6. $db = 'deineDatenbank';
    7. $host = 'deinHost';
    8. $table = 'users';
    9. $con = mysql_connect($host, $user, $pass);
    10. mysql_select_db($db, $con);
    11. $u = mysql_real_escape_string($_GET['u'], $con);
    12. $p = md5($_GET['p']);
    13. $query = "SELECT * FROM $table WHERE (user='$u') AND (pass='$p')";
    14. $result = mysql_query($query, $con);
    15. echo (mysql_num_rows($result) > 0 ? '1' : '0');

    In deinem Programm könnte das dann so aussehen:

    VB.NET-Quellcode

    1. ' Quelle: http://www.a1vbcode.com/vbtip-149.asp
    2. Private Function GenerateHash(ByVal SourceText As String) As String
    3. 'Create an encoding object to ensure the encoding standard for the source text
    4. Dim Ue As New UnicodeEncoding()
    5. 'Retrieve a byte array based on the source text
    6. Dim ByteSourceText() As Byte = Ue.GetBytes(SourceTStext)
    7. 'Instantiate an MD5 Provider object
    8. Dim Md5 As New MD5CryptoServiceProvider()
    9. 'Compute the hash value from the source
    10. Dim ByteHash() As Byte = Md5.ComputeHash(ByteSourceText)
    11. 'And convert it to String format for return
    12. Return Convert.ToBase64String(ByteHash)
    13. End Function
    14. Dim user = "blah", pass = GenerateHash("dasPasswort")
    15. Using client As New System.Net.WebClient()
    16. Dim url = String.Format("http://deineDomain.de/skript.php?u={0}&p={0}", user, pass)
    17. Dim response = client.DownloadString(New Uri(url))
    18. If response = "1" Then
    19. ' erfolgreich
    20. Else
    21. ' nicht erfolgreich
    22. End If
    23. End Using


    Ungetestet, sollte aber funktionieren.
    Cool bräuchte es nur in C#! Wie kann ich auch noch eine Registrier Funktion machen?

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „goraxer“ ()

    1. Es gibt im Internet einen VB to C# Konverter. google danach.
    2. Mach dein Programm selbst und benutz die Forensuche & google. Dieses Thema gab es schon zu genüge (es gibt sogar ein Tutorial hier auf VBP).

    lg
    ScheduleLib 0.0.1.0
    Kleine Lib zum Anlaufen von Code zu bestimmten Zeiten