zoukankan      html  css  js  c++  java
  • 用户登录经典代码

    private void btnLogin_ServerClick(object sender, System.EventArgs e)
            
    {
                SqlConnection con;
                
    string sql;
                SqlCommand cmd;
                
    string id;

                con 
    = new SqlConnection("data source=(local)\\NetSdk;initial catalog=FriendsData;user id=sa");
                sql 
    = "SELECT UserID FROM [User] WHERE Login='{0}' and Password='{1}'";
                
                
    // Format the string with the values provided
                sql = String.Format(sql, txtLogin.Value, txtPwd.Value);
                cmd 
    = new SqlCommand(sql, con);
                con.Open();

                
    try 
                
    {
                    
    // Retrieve the UserID
                    id = (string) cmd.ExecuteScalar();
                }

                
    finally 
                
    {
                    con.Close();
                }


                
    if (id != null)
                
    {
                    
    // Set the user as authenticated and send him to the page originally requested.
                    FormsAuthentication.RedirectFromLoginPage(id, chkPersist.Checked);
                }

                
    else
                
    {
                    
    this.pnlError.Visible = true;
                    
    this.lblError.Text = "Invalid user name or password!";
                }

            }

  • 相关阅读:
    Clipper库中文文档详解
    JavaScript-Clipper.js
    安装Scrapy遇到的问题
    Python中if __name__ == '__main__'的使用
    写出一段Python代码实现删除一个list里面的重复元素
    Python 内置函数(反射类)
    Python 内置函数(集合操作,IO操作)
    Python 内置函数(数学运算类,逻辑判断类)
    Python 推导式(列表推导式,字典推导式,集合推导式)
    Python 闭包和装饰器
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172519.html
Copyright © 2011-2022 走看看