login.aspx.cs

来自「electronic CURRICULUM VITAE」· CS 代码 · 共 82 行

CS
82
字号
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{

    public void checkUser(String username, String password)
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringUser"].ConnectionString);
            cmd.CommandText = @"select [username],[password] from [Seeker]";
            cmd.Connection.Open();
            SqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                string name = reader[0].ToString();
                string pass = reader[1].ToString();
                if ((name.Equals(username)) && (pass.Equals(password)))
                {
                    Response.Redirect("personalInfo.aspx");

                }

            }
            reader.Close();
            cmd.Connection.Close();
           // Response.Redirect("Login.aspx");
        }
        //////////////////////////////////////////////////////////

        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionStringUser"].ConnectionString);
            cmd.CommandText = @"select [username],[password] from [Company]";
            cmd.Connection.Open();
            SqlDataReader reader1 = cmd.ExecuteReader();
            while (reader1.Read())
            {
                string name = reader1[0].ToString();
                string pass = reader1[1].ToString();
                if ((name.Equals(username)) && (pass.Equals(password)))
                {
                    Response.Redirect("SearchCVs.aspx");

                }
            }

            reader1.Close();
            cmd.Connection.Close();

            Response.Redirect("Login.aspx");
        }
    }
    


    protected void submit_Click(object sender, EventArgs e)
    {
        String n = this.userName.Text;
        String p = this.passWord.Text;
        
        checkUser(n, p);

    }


    protected void Page_Load(object sender, EventArgs e)
    {

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?