Imports System.Data.OleDb Public Class Connexion Private Shared _connexion As OleDbConnection Public Shared Sub Initialiser(ByVal path As String) _connexion = New OleDbConnection _connexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";" End Sub Public Shared Sub Open() If _connexion.State = ConnectionState.Closed Then _connexion.Open() End If End Sub Public Shared Function Connexion() As OleDbConnection Return _connexion End Function End Class
Public Shared Sub Initialiser(ByVal path As String) _connexion = New OleDbConnection _connexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";" End Sub
Public Shared Function Connexion() As OleDbConnection Return _connexion End Function
Connexion.Open()
Private Sub btnCreationCompte_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnCreationCompte.Click If Me.txtNomCreation.Text = String.Empty Then Me.lblErreur.Text = "Nom est obligatoire" Exit Sub End If If Me.txtPrenomCreation.Text = String.Empty Then Me.lblErreur.Text = "Prénom est obligatoire" Exit Sub End If If Me.txtLoginCreation.Text = String.Empty Then Me.lblErreur.Text = "Login est obligatoire" Exit Sub End If If Me.txtMPCreation.Text = String.Empty Then Me.lblErreur.Text = "Mot de passe est obligatoire" Exit Sub End If If Me.txtConfirmationCreation.Text = String.Empty Then Me.lblErreur.Text = "La confirmation du mot de passe est obligatoire" Exit Sub End If If String.Compare(Me.txtMPCreation.Text, Me.txtConfirmationCreation.Text) <> 0 Then Me.lblErreur.Text = "La confirmation de mot de passe est incorrecte. Veuillez réessayer." Me.txtConfirmationCreation.Focus() Me.txtConfirmationCreation.SelectAll() Exit Sub End If If SupHerbesBibliotheque.Utilisateur.LoginExists(Me.txtLoginCreation.Text) Then Me.lblErreur.Text = "Ce login est déjà enregistré. Veuillez réessayer." Me.txtLoginCreation.Focus() Me.txtLoginCreation.SelectAll() Exit Sub End If If SupHerbesBibliotheque.Utilisateur.Inserer(Me.txtNomCreation.Text, Me.txtPrenomCreation.Text, Me.txtLoginCreation.Text, Me.txtMPCreation.Text) Then MessageBox.Show("Opération terminée avec succès ", SupHerbesBibliotheque.Divers.TitreMessage, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1) frmMidi.Enabled = True Me.Close() End If End Sub
Private Sub btnModifierCompte_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModifierCompte.Click SupHerbesBibliotheque.Utilisateur.Modifier(Me.txtNomModification.Text, Me.txtPrenomModification.Text, utilisateur.Login, Me.txtLoginModofication.Text, Me.txtNouveauMPModification.Text, Me.chkModifierMotPasse.Checked) End Sub
Dois je stocker la valeur du mot de passe dans un fichier ou comment ?
Imports System.Data Imports System.Data.OleDb Public Class Utilisateur Private _nom As String Private _prenom As String Private _login As String Private _motPasse As String Public Property Nom() As String Get Return Me._nom End Get Set(ByVal value As String) Me._nom = value End Set End Property Public Property Prenom() As String Get Return Me._prenom End Get Set(ByVal value As String) Me._prenom = value End Set End Property Public Property Login() As String Get Return Me._login End Get Set(ByVal value As String) Me._login = value End Set End Property Public Property MotPasse() As String Get Return Me._motPasse End Get Set(ByVal value As String) Me._motPasse = value End Set End Property Sub New(ByVal login As String, ByVal motPasse As String) SupHerbesBibliotheque.Connexion.Open() Dim querString As String querString = "SELECT * FROM UTILISATEURS WHERE [LOGIN]=? AND [MOTPASSE]=?" Dim command As New OleDb.OleDbCommand(querString, SupHerbesBibliotheque.Connexion.Connexion) Dim parNom As New OleDb.OleDbParameter parNom.ParameterName = "LOGIN" parNom.OleDbType = OleDb.OleDbType.VarWChar parNom.Direction = ParameterDirection.Input parNom.Value = login command.Parameters.Add(parNom) Dim parMotPasse As New OleDb.OleDbParameter parMotPasse.ParameterName = "MOTPASSE" parMotPasse.OleDbType = OleDb.OleDbType.VarWChar parMotPasse.Direction = ParameterDirection.Input parMotPasse.Value = CrypterMotDePasse(motPasse) command.Parameters.Add(parMotPasse) Dim dr As OleDb.OleDbDataReader = command.ExecuteReader While dr.Read Me._nom = dr.GetValue(0) Me._prenom = dr.GetValue(1) End While Me._login = login Me._motPasse = motPasse End Sub Sub New() End Sub ''' <summary> ''' Permet de crypter le mot de passe. ''' </summary> ''' ''' <returns></returns> ''' <remarks></remarks> Private Shared Function CrypterMotDePasse(ByVal password As String) As String Dim encodedPassword As String = password Dim hash As Security.Cryptography.HMACSHA1 = New Security.Cryptography.HMACSHA1() hash.Key = New Byte() {12, 34, 1, 100, 99, 13, 33, 56, 93, 93, 7, 3, 77, 19, 12, 12, 98, 111, 25, 35} 'HexToByte(machineKey.ValidationKey) encodedPassword = Convert.ToBase64String(hash.ComputeHash(System.Text.Encoding.Unicode.GetBytes(password))) Return encodedPassword End Function ''' <summary> ''' Vérifie si le login est déjà existe. ''' </summary> ''' ''' <returns></returns> ''' <remarks></remarks> Public Shared Function LoginExists(ByVal login As String) As Boolean SupHerbesBibliotheque.Connexion.Open() Dim querString As String querString = "SELECT COUNT(*) FROM UTILISATEURS WHERE [LOGIN]=?" Dim command As New OleDb.OleDbCommand(querString, SupHerbesBibliotheque.Connexion.Connexion) Dim parNom As New OleDb.OleDbParameter parNom.ParameterName = "LOGIN" parNom.OleDbType = OleDb.OleDbType.VarWChar parNom.Direction = ParameterDirection.Input parNom.Value = login command.Parameters.Add(parNom) If command.ExecuteScalar() = 0 Then Return False Else Return True End Function Public Shared Function UtilisateurValide(ByVal login As String, ByVal motPasse As String) As Boolean SupHerbesBibliotheque.Connexion.Open() Dim querString As String querString = "SELECT COUNT(*) FROM UTILISATEURS WHERE [LOGIN]=? AND [MOTPASSE]=?" Dim command As New OleDb.OleDbCommand(querString, SupHerbesBibliotheque.Connexion.Connexion) Dim parNom As New OleDb.OleDbParameter parNom.ParameterName = "LOGIN" parNom.OleDbType = OleDb.OleDbType.VarWChar parNom.Direction = ParameterDirection.Input parNom.Value = login command.Parameters.Add(parNom) Dim parMotPasse As New OleDb.OleDbParameter parMotPasse.ParameterName = "MOTPASSE" parMotPasse.OleDbType = OleDb.OleDbType.VarWChar parMotPasse.Direction = ParameterDirection.Input parMotPasse.Value = CrypterMotDePasse(motPasse) command.Parameters.Add(parMotPasse) If command.ExecuteScalar() = 0 Then Return False Else Return True End Function Public Shared Function Inserer(ByVal nom As String, ByVal prenom As String, ByVal login As String, ByVal motpasse As String) Try SupHerbesBibliotheque.Connexion.Open() Dim querString As String querString = "INSERT INTO Utilisateurs([Nom], [Prenom], [Login], [MotPasse]) VALUES (?, ?, ?, ?)" Dim command As New OleDb.OleDbCommand(querString, SupHerbesBibliotheque.Connexion.Connexion) Dim parNom As New OleDb.OleDbParameter parNom.ParameterName = "Nom" parNom.OleDbType = OleDb.OleDbType.VarWChar parNom.Direction = ParameterDirection.Input parNom.Value = nom command.Parameters.Add(parNom) Dim parPrenom As New OleDb.OleDbParameter parPrenom.ParameterName = "Prenom" parPrenom.OleDbType = OleDb.OleDbType.VarWChar parPrenom.Direction = ParameterDirection.Input parPrenom.Value = prenom command.Parameters.Add(parPrenom) Dim parLogin As New OleDb.OleDbParameter parLogin.ParameterName = "Login" parLogin.OleDbType = OleDb.OleDbType.VarWChar parLogin.Direction = ParameterDirection.Input parLogin.Value = login command.Parameters.Add(parLogin) Dim parMotPasse As New OleDb.OleDbParameter parMotPasse.ParameterName = "MotPasse" parMotPasse.OleDbType = OleDb.OleDbType.VarWChar parMotPasse.Direction = ParameterDirection.Input parMotPasse.Value = CrypterMotDePasse(motpasse) command.Parameters.Add(parMotPasse) command.ExecuteNonQuery() Return True Catch ex As Exception Return False End Try End Function Public Shared Function Modifier(ByVal nom As String, ByVal prenom As String, ByVal ancienLogin As String, ByVal nouveauLogin As String, ByVal motPasse As String, ByVal motPasseModifier As Boolean) Try SupHerbesBibliotheque.Connexion.Open() Dim querString As String If motPasseModifier = True Then querString = "UPDATE UTILISATEURS SET [Nom]=? , [Prenom]=?, [Login]=? , [MotPasse]=? WHERE Login='" & ancienLogin & "'" Else querString = "UPDATE UTILISATEURS SET [Nom]=? , [Prenom]=?, [Login]=? WHERE Login='" & ancienLogin & "'" End If Dim command As New OleDb.OleDbCommand(querString, SupHerbesBibliotheque.Connexion.Connexion) Dim parNom As New OleDb.OleDbParameter parNom.ParameterName = "Nom" parNom.OleDbType = OleDb.OleDbType.VarWChar parNom.Direction = ParameterDirection.Input parNom.Value = nom command.Parameters.Add(parNom) Dim parPrenom As New OleDb.OleDbParameter parPrenom.ParameterName = "Prenom" parPrenom.OleDbType = OleDb.OleDbType.VarWChar parPrenom.Direction = ParameterDirection.Input parPrenom.Value = prenom command.Parameters.Add(parPrenom) Dim parNouveauLogin As New OleDb.OleDbParameter parNouveauLogin.ParameterName = "Login" parNouveauLogin.OleDbType = OleDb.OleDbType.VarWChar parNouveauLogin.Direction = ParameterDirection.Input parNouveauLogin.Value = nouveauLogin command.Parameters.Add(parNouveauLogin) If motPasseModifier = True Then Dim parMotPasse As New OleDb.OleDbParameter parMotPasse.ParameterName = "MotPasse" parMotPasse.OleDbType = OleDb.OleDbType.VarWChar parMotPasse.Direction = ParameterDirection.Input parMotPasse.Value = CrypterMotDePasse(motPasse) command.Parameters.Add(parMotPasse) End If command.ExecuteNonQuery() Return True Catch ex As Exception Return False End Try End Function End Class
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Shared Sub Initialiser(ByVal path As String) _connexion = New OleDbConnection _connexion.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";" End Sub
Private Sub frmMidi_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ''Initialiser la connexion. SupHerbesBibliotheque.Connexion.Initialiser("CheminDeTaBaseDeDonnees") End Sub
Public Shared Function UtilisateurValide(ByVal login As String, ByVal motPasse As String) As Boolean SupHerbesBibliotheque.Connexion.Open() Dim querString As String querString = "SELECT COUNT(*) FROM UTILISATEURS WHERE [LOGIN]=? AND [MOTPASSE]=?" Dim command As New OleDb.OleDbCommand(querString, SupHerbesBibliotheque.Connexion.Connexion) Dim parNom As New OleDb.OleDbParameter parNom.ParameterName = "LOGIN" parNom.OleDbType = OleDb.OleDbType.VarWChar parNom.Direction = ParameterDirection.Input parNom.Value = login command.Parameters.Add(parNom) Dim parMotPasse As New OleDb.OleDbParameter parMotPasse.ParameterName = "MOTPASSE" parMotPasse.OleDbType = OleDb.OleDbType.VarWChar parMotPasse.Direction = ParameterDirection.Input parMotPasse.Value = CrypterMotDePasse(motPasse) command.Parameters.Add(parMotPasse) If command.ExecuteScalar() = 0 Then Return False Else Return True End Function
If SupHerbesBibliotheque.Utilisateur.UtilisateurValide(Me.txtLoginCreation.Text, Me.txtMPCreation.Text) Then 'Traitement lorsque les informations sont correctes, il existe un utilisateur avec ces informations dans notre table des utilisateurs dans la base de données. 'Vous pouvez mettre par exemple : Me.Close() Else 'S'il n y a pas d'utilisateurs avec ces informations 'Vous pouvez mettre par exemple : Me.lblErreur.Text = "Le login ou le mot de passe est incorrect. Veuillez réessayer." End If
If Utilisateur.UtilisateurValide(Me.txtLoginCreation.Text, Me.txtMPCreation.Text) Then frmMidi.UtilisateurCourant = New Utilisateur(Me.txtLoginCreation.Text, Me.txtMPCreation.Text) Me.Close()
Private _utilisateurCourant As New Utilisateur Public Property UtilisateurCourant() As Utilisateur Get Return Me._utilisateurCourant End Get Set(ByVal value As Utilisateur) Me._utilisateurCourant = value End Set End Property
frmMidi.UtilisateurCourant, on parle de l'utilisateur en ligne. Ok??
Utilisateur.Modifier(Me.txtNomModification.Text, Me.txtPrenomModification.Text, utilisateur.Login, Me.txtLoginModofication.Text, Me.txtNouveauMPModification.Text, Me.chkModifierMotPasse.Checked)
(AppDomain.CurrentDomain.SetupInformation.ApplicationBase & "\NomDeLaBaseAcces.mdb")
Connexion.Initialiser(AppDomain.CurrentDomain.SetupInformation.ApplicationBase & "\NomDeLaBaseAcces.mdb")