Login problems with encrypted passwords

Discussion in 'ASP.NET / ASP.NET Core' started by mike72, Sep 6, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. I have some login code that works fine on several local machines, but always fails when uploaded. I think it has something to do with encryption. Here is the Submit_Click event which when the code is uploaded always sets newUser to null, so I always get 'Login failed'. PhilePrincipal.ValidateLogin is called to set the value of newUser and this involves encryption (see code below). That is the only reason I can think of why it is not working. Any ideas?

    private void Submit_Click(object sender, System.EventArgs e)
    {
    PhilePrincipal newUser = PhilePrincipal.ValidateLogin( EmailAddress.Text, Password.Text );
    if (newUser == null)
    {
    LoginResult.Text = "Login failed for " + EmailAddress.Text;
    LoginResult.Visible = true;
    }
    else
    {
    Context.User = newUser;
    FormsAuthentication.SetAuthCookie( EmailAddress.Text, true );
    Response.Redirect("default.aspx");
    }
    }

    public static PhilePrincipal ValidateLogin(string emailAddress, string password)
    {
    Configuration.ModuleSettings moduleSettings = Configuration.ModuleConfig.GetSettings();
    int newID;
    byte[] cryptPassword = EncryptPassword( password );

    Data.User dataUser = new Data.User( moduleSettings.ConnectionString );
    if ( (newID = dataUser.ValidateLogin(emailAddress, cryptPassword)) > -1 )
    return new PhilePrincipal( newID );
    else
    return null;
    }

    public static byte[] EncryptPassword(string password)
    {
    UnicodeEncoding encoding = new UnicodeEncoding();
    byte[] hashBytes = encoding.GetBytes( password );
    // compute SHA-1 hash.
    SHA1 sha1 = new SHA1CryptoServiceProvider();
    byte[] cryptPassword = sha1.ComputeHash ( hashBytes );
    return cryptPassword;
    }


    Cheers,

    Mike
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page