Please help me how I create the login form using c# in asp.net

Dani AI

Generated

Short roadmap and recommendation: for a secure login today prefer the built-in Identity systems instead of hand-rolled checks. For new projects target ASP.NET Core and use ASP.NET Core Identity; for existing Web Forms/MVC on .NET Framework use ASP.NET Identity (the Microsoft-recommended replacement for the older Membership/FormsAuth approach). Identity gives salted+hashed passwords, cookie-based sign-in, lockout, 2FA and external providers so you don’t have to implement those primitives yourself. (learn.microsoft.com)

Why the example posts are risky: ’s ADO code concatenates SQL and compares plaintext values — that permits SQL injection and unsafe password storage. ’s JavaScript-only “login” runs in the browser and provides no server-side authentication at all. Never trust client-side checks; always validate and authenticate on the server, and never store plaintext passwords. Use parameterized queries/ORMs and a modern password hasher. (pentest.y-security.de)

Concrete, small options to get started:

  • Fast, recommended (ASP.NET Core): create a project with “Individual User Accounts” or add Identity and use the SignInManager to authenticate:
    var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, lockoutOnFailure: true);
    if (result.Succeeded) { return RedirectToAction("Index","Home"); }
  • Minimal legacy approach (if you cannot use Identity yet): use parameterized queries and verify against a stored hash (do not compare plaintext):
    using(var cmd = new SqlCommand("SELECT PasswordHash FROM Users WHERE UserName=@u", conn)) {
    cmd.Parameters.Add("@u", SqlDbType.NVarChar,256).Value = username;
    var hash = (string)cmd.ExecuteScalar();
    if (hash != null && VerifyPassword(hash, password)) { /* sign in */ }
    }

    For scaffolding and step-by-step Identity guidance see Microsoft’s Identity resources. (learn.microsoft.com)

Quick checklist/tips: always use HTTPS, set cookies Secure+HttpOnly+SameSite, enable account lockout and (if possible) two‑factor, enforce strong password rules, and log auth events. If migrating from old Membership, follow Microsoft’s migration guidance rather than reusing insecure code. (cheatsheetseries.owasp.org)

Recommended Answers

All 5 Replies

take the idea from the following code:

using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OleDb;

public partial class _Default : System.Web.UI.Page 
{
    //OleDbConnection con = new OleDbConnection(ConfigurationSettings .AppSettings ["conn"]);
    OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\WebSite\\Registration\\App_Data\\web.mdb;Persist Security Info=True");
    
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Equals ("") || TextBox2.Text.Equals ("") )
        {
            Response.Write("Fill User name and password");
        }
        else 
        {
            string sel = "select *from signup where user_id='" + TextBox1.Text.ToString() + "'";
            OleDbDataAdapter oda = new OleDbDataAdapter(sel, con);
            DataTable dt = new DataTable();
            oda.Fill(dt);
            string du = dt.Rows[0]["user_id"].ToString();
            string dp = dt.Rows[0]["password"].ToString();
            string tu = TextBox1.Text.ToString();
            string tp = TextBox2.Text.ToString();
            if (du.Equals(tu) && dp.Equals(tp))
            {
                Session["ses"] = TextBox1.Text;
                Response.Redirect("detail.aspx");
            }
            else
            {
               Response.Write("Invalid User name or password");
            }

        }
        
    }
}

hi,
this is a simple login script
try this

<html>
<head>
SCRIPT LANGUAGE="Javascript">




var COLOR = 999999
var woot = 0
function stoploop() {
document.bgColor = '#000000';
clearTimeout(loopID);
}
function loopBackground() {
if (COLOR > 0) {
document.bgColor = '#' + COLOR
COLOR -= 111111
loopID = setTimeout("loopBackground()",1)
} else {
document.bgColor = '#000000'
woot += 10
COLOR = 999999
COLOR -= woot
loopID = setTimeout("loopBackground()",1)
   }
}


</head>
<body bgcolor="#F8F8FF">



<CENTER>
<FORM NAME="background">
<INPUT TYPE="button" VALUE="Start bgColor WARP"
onClick="loopBackground()">
<br>
<input type="button" value="Stop bgColor WARP" onClick="stoploop()">
</FORM>
</CENTER>


<br><br><br><BR><center><img src="" alt="The Logo" /></center> 

<br><br><script language="javascript">

function pasuser(form) {
if (form.id.value=="") { 
if (form.pass.value=="") {              
location="search.html" 
} else {
alert("Invalid Password")
}
} else {  alert("Invalid UserID")
}
}


<center>
<table bgcolor="#F8F8FF" cellpadding="12" border="0">
<tr><td colspan="2"><center><h1><b>Login
</b></h1></center></td></tr>
<tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="login"><input
name="id" type="text"></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
type="password"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><Left><br><input
type="Reset"></form></td></tr></table></left>
</body></html>

this is amazing..thank u...

Please help me how I create the login form using c# in asp.net

There is a step by step simple tutorial here

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.