PDA

View Full Version : [ASP.NET]Login Forms Authentication con SHA1


Nix17
15-03-2011, 12:00
Buongiorno, ho un problema nell'eseguire un login abilitando il formato della password come SHA1 nel web.config, faccio l'hashing della password ma quando vado a fare il login non mi riconosce, il web config č cosė configurato

<?xml version="1.0"?>
<!--
Per ulteriori informazioni su come configurare l'applicazione ASP.NET, visitare il sito Web all'indirizzo
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>

<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="~/Login.aspx">
<credentials passwordFormat = "SHA1">
<user name="utente1" password="D012F68144ED0F121D3CC330A17EEC528C2E7D59"/>
<user name="utente2" password="B3C8A9B5A8CA17D0B2A8E8540C196F21010A26E1"/>
</credentials>
</forms>
</authentication>

</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>


mentre il codice con cui creo l'hash e con cui eseguo il login č questo

protected string HashingPassword(string PasswordID)
{
_PasswordSHA1 = FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordID, "SHA1");
return _PasswordSHA1;
}

protected void EseguiLogin()
{
string PasswordID = null;

if ((txtUser.Text != "") && (txtUser.Text != null) && (txtPassword.Text != "") && (txtPassword.Text != null))
{
_UserName = txtUser.Text;
PasswordID = txtPassword.Text;
HashingPassword(PasswordID);

if (FormsAuthentication.Authenticate(_UserName, _PasswordSHA1))
{
LogInRiuscito();
}
else
{
txtUser.Text = "";
lblLogInBad.Text = "";
lblLogInBad.Text = "Username o Password incorretti!";
lblLogInBad.Visible = true;
}


Ogni volta il login non riesce ritornandomi sempre username e password sbagliati, sapreste darmi una mano?