Je ne comprends pas pourquoi ca ne fonctionne pas en fait il refuse systématiquement de m'authentifier meme avec le bon mot de passe
login.aspx
<%@ Import Namespace="System.Web.Security"%>
<%@ Import Namespace="System.Data.SqlClient"%>
<%@ Page Language="VB" Debug="true" Explicit="true" %>
<script language="VB" runat=server>
sub Login_Click(Src As Object, E As EventArgs)
Msg2.Text = tPass.Text
If(Authentifier(tUser.Text, tPass.Text))
FormsAuthentication.RedirectFromLoginPage(tUser.Text, false)
Else
Msg.Text = "Erreur d'authentification"
end if
end sub
function Authentifier(sUser as string, sPassword as string) as boolean
dim bResult as boolean = false
sPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(sPassword, "MD5")
Dim oConnection As System.Data.SqlClient.SqlConnection
oConnection = New System.Data.SqlClient.SqlConnection()
Dim sConnectionString As String
sConnectionString = "Server=ALEY4;Initial Catalog=Intranet;uid=intranet;password=aley2003"
oConnection.ConnectionString = sConnectionString
Dim oCommand as New System.Data.SqlClient.SqlCommand
Dim sCommand As String
sCommand = "SELECT * FROM t_user WHERE login_user = '" + sUser + "'"
Msg2.Text = sUser
oCommand = New System.Data.SqlClient.SqlCommand(sCommand, oConnection)
try
oConnection.Open()
dim drUser as SqlDataReader = oCommand.ExecuteReader()
if(drUser("password_user").ToString() = sPassword)
bResult = true
end if
catch
bResult = false
end try
oConnection.Close()
return bResult
end function
</script>
<html>
<body>
<form runat=server>
<h3><font face="Verdana">Page de connexion</font></h3>
<table>
<tr>
<td>Login :</td>
<td><asp:TextBox id="tUser" runat="server"/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="tUser" Display="Static" ErrorMessage="*" runat=server/></td>
</tr>
<tr>
<td>Mot de passe :</td>
<td><asp:TextBox id="tPass" runat="server"/></td>
<td><ASP:RequiredFieldValidator ControlToValidate="tPass" Display="Static" ErrorMessage="*" runat=server/></td>
</tr>
</table>
<asp:button text="Connexion" OnClick="Login_Click" runat=server/>
<p>
<asp:Label id="Msg" ForeColor="red" Font-Name="Verdana" Font-Size="10" runat=server />
<asp:Label id="Msg2" ForeColor="red" Font-Name="Verdana" Font-Size="10" runat=server />
</form>
</body>
</html>
default.aspx
<%@ Import Namespace="System.Web.Security " %>
<%@ Page Language="VB" Debug="true" %>
<html>
<script language="VB" runat=server>
Sub Page_Load(Src As Object, E As EventArgs)
Welcome.Text = "Bonjour, " + User.Identity.Name
End Sub
Sub Signout_Click(Src As Object, E As EventArgs)
FormsAuthentication.SignOut()
Response.Redirect("login.aspx")
End Sub
</script>
<body>
<h3><font face="Verdana">Utilisation de l'authentification par cookie</font></h3>
<form runat=server>
<h3><asp:label id="Welcome" runat=server/></h3>
<asp:button text="Déconnexion" OnClick="Signout_Click" runat=server/>
</form>
</body>
</html>
Si vous voyez merci de me dire