page d'authentification avec sql server
slt à tous!
je bloque depuis 2 jours sur ce bout de code, en voulant faire plus simple finalement j'y comprend rien.
En faite ,je cherche juste une page d'authentique à partir d'un champ EMAIL (dans un dropdownlist) et du mot de passe saisi dans un textbox.
voici le code coté VB.net
Code:
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
|
Imports System.IO
Imports System
Imports System.Data
Imports System.Data.SqlClient
Partial Class LoginAdmin
Inherits System.Web.UI.Page
Dim DBConn As New Data.SqlClient.SqlConnection("Initial Catalog=ARIANE;Data Source=SRV-BACKUP;Trusted_Connection=True")
Dim cn As Data.SqlClient.SqlCommand
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
DBConn.Open()
End Sub
Sub BtnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Rs As New ADODB.Recordset
Dim SQL As String
SQL = "select * from EMPLOYE where EMAIL='" & DropDownList2.SelectedValue & "' and PASSWORD='" & passwd.text & "'"
Rs.Open(SQL, cn)
With Rs
If passwd.text = "password" Then
Response.Redirect("CreatePassword.aspx?EMAIL=" + DropDownList2.Text)
Else
If (.BOF And .EOF) Then
Response.Redirect("AdministrerOrdreMission.aspx?EMAIL=" + DropDownList2.Text)
Else
message.Text = ("Mot de passe incorrect! Veuillez recommencer.")
End If
End If
End With
End Sub
End Class |
J'ai déjà un code du même genre mais avec une base access, mais j'arrive pas à bien modifier ce qu'il faut:
Code:
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
| Imports System.Data.OleDb
Imports System.Data
Imports System.IO
Imports System
Partial Class LoginAdmin
Inherits System.Web.UI.Page
Dim MaConnexion As New Data.OleDb.OleDbConnection
Dim cn As New ADODB.Connection
Function Existe(ByVal Table As String, ByVal Condition As String) As Boolean
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\WebSetup2\App_Data\Bdd.mdb;"
Dim Rs As New ADODB.Recordset
Dim SQL As String
Dim Resultat As Boolean
cn.Open()
'MaConnexion.Open()cbt
'Call MaConnexion()²²&éé"
SQL = "Select * From " & Table
If Condition <> "" Then SQL = SQL & " Where " & Condition
Rs.Open(SQL, cn)
Resultat = False
With Rs
If Not (.BOF And .EOF) Then
Resultat = True
End If
End With
Existe = Resultat
cn.Close()
End Function
Sub BtnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
If Existe("Employés", "passwd='" & passwd.Text & "' and email='" & DropDownList2.SelectedValue & "'") And passwd.Text = "password" Then
Response.Redirect("CreatePassword.aspx?Email=" + DropDownList2.Text)
Else
If Existe("Employés", "passwd='" & passwd.Text & "' and email='" & DropDownList2.SelectedValue & "'") Then
Response.Redirect("AdministrerOrdreMission.aspx?Email=" + DropDownList2.Text)
Else
message.Text = ("Mot de passe incorrect! Veuillez recommencer.")
End If
End If
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class |