Asp.net中的登录表单验证 [英] Login Form Validation in Asp.net

查看:97
本文介绍了Asp.net中的登录表单验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我会用简单的英语问一个问题,因为我是该领域的初学者并从事我的BCS项目.

我如何验证包含用户ID和密码的登录表单.当用户输入ID和密码时,它与sqlDatabase匹配.我需要它的源代码.在哪个页面中,我将使用该代码.

Sir I will ask a question in a simple English because i m beginner in this field and doing my BCS Projects.

How I can Validate my Login form which contain userId and Password. when user enter ID and password it match with sqlDatabase. i need a source code for it.and in which page i will use the code.

推荐答案

创建登录表单.添加用户名和密码文本框.
在后面的代码(login.aspx.cs文件)中的登录按钮click事件中执行以下操作
Create a Login form. Add User Name and Password text box.
In code behind(login.aspx.cs file) login button click event do the following
SqlConnection con=new SqlConnection("Your Connection String");

if (con.State == ConnectionState.Open)
  {
    qry = "";
    qry = "select Password,UserID from tblUsers where UserID= ''" +      txtUserName.Text.Trim().Replace("''", "''''") + "'' and Password=''" + txtPassword.Text.Trim().Replace("''", "''''") + "''";
    SqlCommand cmd = new SqlCommand (qry, con);
    SqlDataReader reader = cmd.ExecuteReader();
    if (reader.Read())
    {
        //redirect to other page
    }
    else
    {
      MessageBox.Show("Please check User Name and Password");
      txtUserName.Focus();
    }
 }


这篇关于Asp.net中的登录表单验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆