1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
| Public Class Formconnexion
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim con As New SqlConnection
Dim cmd As New SqlCommand
Try
Dim log1 As String = UsernameTextBox.Text
Dim mp As String = PasswordTextBox.Text
Dim mp2 As String
con.ConnectionString = "Data Source=USER-PC\sqlexpress;Initial Catalog=dossier medical;Integrated Security=True"
con.Open()
cmd.Connection = con
cmd.CommandText = "SELECT mdp FROM medecin where login = '" + log1 + "'"
Dim lrd As SqlDataReader = cmd.ExecuteReader()
While lrd.Read()
mp2 = lrd.GetString(0)
MsgBox("mp2")
If (mp2 = mp) Then
MDIParent1.Show()
'Me.Close()
Else
MsgBox("Verifier votre login et mot de passe")
End If
End While
Catch ex As Exception
MessageBox.Show("Error while retrieving records on table..." & ex.Message, "Load Records")
Finally
con.Close()
End Try
Dim log As String = UsernameTextBox.Text
Dim pwd As String = PasswordTextBox.Text
If (verifier_Existance(log, pwd)) Then
MDIParent1.Show()
Me.Hide()
Else
MessageBox.Show("Echec d'authentification", "Erreur", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
End Sub
Public Function verifier_Existance(ByVal log1 As String, ByVal pd As String) As Boolean
'acce au fichier
Try
Dim chlog As String = ""
Dim chpwd As String = ""
Dim monStreamreader As StreamReader = File.OpenText("C:\Users\user\Documents\Visual Studio 2008\Projects\dossier medical\logpwd.txt")
Do
chlog = monStreamreader.ReadLine()
chpwd = monStreamreader.ReadLine()
Loop Until chlog Is Nothing And chpwd Is Nothing
monStreamreader.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
If (log1.Equals("chlog") And pd.Equals("chpwd")) Then
Return True
Else
Return False
End If
End Function
End Class |
Partager