Hi guys,

I am in the process of creating a login form in ASP.Net and I have not written any code for it yet bcos I dont know how to go about doing it.In the past I have created basic login forms in ASP.net by redirecting them to a page if the login was successful or display them a failed message in a label control if it was a invalid login. Now Im thinking of

  • Displaying the failed message in a jQuery modal popup
  • In the same popup provide a textbox control asking them to put their email address and a button to send an email to the admin asking for their password,then display a message in a label control saying the email has been sent to the admin.

If anyone knows of any tutorials or articles explaining how to do this ,please let me know.Im also googling for steps to execute this.

Thank You

Dani AI

Generated

Good direction from and useful replies from and . Combine client-side checks for a smoother UX (as suggested) with an AJAX-backed server check (as shows), but keep authentication decisions on the server. Have the server issue the authentication cookie and return a small JSON payload (for example { "success": true, "redirectUrl": "/home", "message": "..." }). The client should simply interpret that JSON and either do a location.replace to the returned URL or open a modal with the server message. Avoid brittle client-side href manipulation or trying to enforce security in JavaScript.

For the "forgot password" flow: do not email passwords to an admin. Use a token-based reset that is single-use and time-limited. Typical flow:

  • POST the email from the modal to a reset endpoint.
  • If the account exists, generate a cryptographically secure token, store a hashed token with an expiry (or use your framework's token API), and send the user an HTTPS link containing the token.
  • The reset page validates the token server-side, accepts a new password, then invalidates the token immediately.

Security checklist and gotchas: always use HTTPS; validate everything server-side; include anti-forgery protection on AJAX posts; rate-limit or add CAPTCHA to the reset endpoint; log reset attempts and lock accounts on abuse; set auth cookies with Secure, HttpOnly and appropriate SameSite attributes; be mindful of whether you reveal account existence in reset responses (consider a generic reply to avoid user enumeration). For platform guidance, consult framework identity docs and established best practices such as the OWASP Forgot Password Cheat Sheet and OWASP Authentication Cheat Sheet and the ASP.NET Identity docs for built-in token handling.

References: OWASP Forgot Password Cheat Sheet, OWASP Authentication Cheat Sheet, Introduction to ASP.NET Identity.

Recommended Answers

All 2 Replies

Hi guys,

I am in the process of creating a login form in ASP.Net and I have not written any code for it yet bcos I dont know how to go about doing it.In the past I have created basic login forms in ASP.net by redirecting them to a page if the login was successful or display them a failed message in a label control if it was a invalid login. Now Im thinking of

  • Displaying the failed message in a jQuery modal popup
  • In the same popup provide a textbox control asking them to put their email address and a button to send an email to the admin asking for their password,then display a message in a label control saying the email has been sent to the admin.

If anyone knows of any tutorials or articles explaining how to do this ,please let me know.Im also googling for steps to execute this.

Thank You

Hi, once I made the mail control lab. JavaScript checks the textboxes for being fulfilled, emailbox for being valid... If some of them is not, then borders of boxes getting red and explanation marks appearing. This form can be easily rewritten in jQuery. If you are interested, write me an email and I'll send you this lab.

<script type = "text/javascript">

function checkauthen() {

    $.ajax({

        type: "POST",

        url: "CS.aspx/CheckUserName",

        data: '{userName: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',

        contentType: "application/json; charset=utf-8",

        dataType: "json",

        success: OnSuccess,

        failure: function(response) {

            alert(response);

        }

    });

}

function OnSuccess(response) {



    switch (response.d) {

        case "true":



            href.location=querySt( window.location.toString());

            break;

        case "false":



            href.location = "notlogin.aspx";

            break;

        case "error":


            href.location = "error.aspx";

            break;                    

    }

}

function querySt(ji) {
hu = window.location.search.substring(1);
gy = hu.split("&");
for (i=0;i<gy.length;i++) {
ft = gy[i].split("=");
if (ft[0] == ji) {
return ft[1];
}
}

</script>

[System.Web.Services.WebMethod]

public static string CheckUserName(string userName,string password)

{

    string returnValue = string.Empty;

    try

    {

        string consString = ConfigurationManager

                .ConnectionStrings["conString"].ConnectionString;

        SqlConnection conn = new SqlConnection(consString);

        SqlCommand cmd = new SqlCommand("CheckUser", conn);           

        cmd.CommandType = CommandType.StoredProcedure;


        cmd.Parameters.AddWithValue("@UserName", userName.Trim());

        cmd.Parameters.AddWithValue("@password", password.Trim());

        conn.Open();

        returnValue = cmd.ExecuteScalar().ToString();

        conn.Close();

    }

    catch

    {

        returnValue = "error";

    }

    return returnValue;

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.