Comment créer un système de login en VB.NET ?
Système simple
Tout d'abord, commencez par créer une fenêtre ou vous ajouterez :
- Deux Label "Pseudo" et "Mot de passe"
- Deux TextBox à côté des label
- Un bouton
Ensuite, double-cliquez sur le bouton(le code).
Tapez ceci:
If TextBox1.Text "votre nom d'utilisateur" And TextBox2.Text "votre mot de passe" Then
MsgBox("Correct")
Else
MsgBox("Incorrect")
End If
Voilà c'est bon.
A partir d'un fichier
Imaginons que vous avez un fichier comme ça :
Utilisateur1:motdepasse
Utilisateur2:motdepasse2
Refaites une fenêtre comme avant et dans le code tapez ceci :
Dim rd As New System.IO.StreamReader("C:\monfichier.txt")
Dim fich1 As String = rd.ReadAllLines()
Dim cestbon As Boolean = False
For Each utilisateur As String In fich1
Dim usr As String
Dim mdp As String
If TextBox1.Text usr And TextBox2.Text mdp Then
Cestbon = True
Exit For
Else
Cestbon = False
End If
Next
If cestbon Then
MsgBox("Correct")
Else
MsgBox("Incorrect")
End If