ユーザー名とパスワード用の2つのテキストボックスとボタンがあります。認証されたユーザーがログインして別のページにリダイレクトし、ようこそ認証されたユーザー名を表示することを許可したい. または、無効なユーザー名というメッセージを表示する. セッションを使用してこれを実行し、データベースに接続する方法. データベースで構成する方法. 私を助けてください。
My code is
<div id="loginbox">
<div align="center" style="width: 100%;">
</div>--%>
<br />
<label for="username">Username:</label> <input type="text"
id="username" /></li>
<label for="password">Password:</label> <input type="password" id="password" />
<input type="button" runat="server" value="Login">
</form>
My .cs code
protected void btnLogin_onclick(object sender, EventArgs e)
{
string connect = "Data Source=ST0022;Initial Catalog=QuickMove_Globe;Persist
Security Info=True;User ID=sa;Password=good";
string query = "Select Count(*) From Common.Users Where UserID = ? And Password =
?";
int result = 0;
SqlConnection con= new SqlConnection(connect);
SqlCommand cmd = new SqlCommand(query, con);
cmd.Parameters.AddWithValue("UserID",username.Value);
cmd.Parameters.AddWithValue("Password", password.Value);
con.Open();
Session["User"] = username.Value;
result = (int)cmd.ExecuteScalar();
if (result > 0)
{
Response.Redirect("TestPortalPage.aspx");
}
else
{
lbluser.Text = "Invalid credentials";
}
}