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!";
                }

            }

  • 相关阅读:
    树莓派安装aria2轻松下载小资源
    利用树莓派3搭建可以发射无线局域网的微型服务器
    Vue语法
    redis-cluster集群
    分布式锁
    Redis--消息队列
    设计模式---享元模式
    设计模式(单例模式+原型模式)+ c#的内存分配机制
    MVC的ActionFilter
    MVC异常处理的7大场景 + MVC的异常处理的过滤器 + 全局异常
  • 原文地址:https://www.cnblogs.com/ahuang1118/p/172519.html
Copyright © 2011-2022 走看看