ASP.Net - How to Encrypt Password Before Logging In Using Login Control

I am using an ASP.Net control to enter a web application. When the user submits the form, I want to call the function to encrypt the password before ASP.Net submits the authentication information.

I tried adding a client checker to the password field, and if the password is not empty, the .Text password will be replaced with an encrypted value. However, it looks like ASP.Net is still sending the original password for authentication.

I also tried adding the onClick event to the login button to encrypt the password, but ASP.Net still sent the original password for authentication.

Is there any way to do this? Thank!

UPDATE:

I apologize for not understanding this. I need to encrypt the password on the server side.

I do not use ASP.Net membership to encrypt or hash a password when registering a user. The passwordFormat property is set to Clear.

What am I doing:

  • While a new user is logging in, I use a custom function to encrypt the password and save it in the database.
  • When a user tries to log in, I want to use the same function to encrypt the password entered by the user and allow ASP.Net to authenticate the user.

The problem I am facing is that I cannot find a way to call the encryption function before ASP.Net initiates the authentication process.

Hope this makes sense. Thank.

Allen

+3
source share
3 answers

, OnClick. , OnClientClick (OnClick , OnClientClick - ). , javascript , ?

[ ]

, Login, OnAuthenticate:

<asp:Login id="Login1" runat="server" OnAuthenticate="OnAuthenticate">
</asp:Login>

:

private void OnAuthenticate(object sender, AuthenticateEventArgs e) {
    bool authenticated = false;
    String encryptedPassword = Encrypt(Login1.Password);
    authenticated = YourAuthenticationMethod(Login1.UserName, encryptedPassword );

    e.Authenticated = authenticated;
}
private bool YourAuthenticationMethod(String username, String encryptedPassword) {
    //test the encrypted password against that retrieved from your database using the username
}
+1

? , . , , .

- :

public static string createPasswordHash(string pwd)
    {
        return FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5");
    }
+1

, - ASP.NET, . - " #" . HTTP ( , , ), JavaScript " ". , (, ( ) ), #, .

, . , : , , , , - . , , , , , . , , .
, , . , , ( ) - , , . , , - ( ) . , .
, , JavaScript, , (RSA - , ).

0
source

All Articles