Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            HttpCookie login = Request.Cookies["login"]; //получаем из запроса куки по ключу login
            HttpCookie sign  = Request.Cookies["sign"];

            metka  = Request.Cookies["authorize"];
            idtren = Request.Cookies["idtren"];


            if (sign != null && login != null)                                   //проверяем, есть ли у пользователя кукисы
            {
                if (sign.Value == SignGenerator.GetSign(login.Value + "bytepp")) //сравниваем с цифровой подписью
                {
                    cnn2 = new SqlConnection(stroka);
                    cnn2.Open();

                    SqlCommand getname = new SqlCommand("select trener.[ИМЯ] from [MARI].[TRENERI] trener join [MARI].[LogTren] login on login.IDTRENER = trener.IDTRENER where trener.IDTRENER = @id", cnn2);
                    getname.CommandType = CommandType.Text;
                    getname.Parameters.AddWithValue("id", idtren.Value);

                    HttpCookie    name = null;
                    SqlDataReader rdr  = null;
                    rdr = getname.ExecuteReader();

                    while (rdr.Read())
                    {
                        name = new HttpCookie("idtren", Convert.ToString(rdr.GetValue(0)));
                    }
                    rdr.Close();

                    Label1.Text = "Добро пожаловать, " + name.Value + "!";
                    return;
                }
            }

            GridView2.DataBind();
            GridView3.DataBind();
            Response.Redirect("Login.aspx");
        }
Beispiel #2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            Dictionary <string, string> db_user = new Dictionary <string, string>();
            SqlCommand getUsrCred = new SqlCommand("select login.Login, login.Password from MARI.login", conn);

            SqlDataReader sqlReader = null;

            sqlReader = getUsrCred.ExecuteReader();

            while (sqlReader.Read())
            {
                db_user.Add(Convert.ToString(sqlReader["Login"]), Convert.ToString(sqlReader["Password"]));
            }

            if (sqlReader != null)
            {
                sqlReader.Close();
            }

            Dictionary <string, string> db_trener = new Dictionary <string, string>();
            SqlCommand getTrenCred = new SqlCommand("select Login, Password from MARI.LogTren", conn);

            sqlReader = getTrenCred.ExecuteReader();

            while (sqlReader.Read())
            {
                db_trener.Add(Convert.ToString(sqlReader["Login"]), Convert.ToString(sqlReader["Password"]));
            }

            if (sqlReader != null)
            {
                sqlReader.Close();
            }

            try {
                if (TextBox2.Text == db_user[TextBox1.Text.Trim()]) //словарь сравнивает значение пароля в текстбоксе и в словаре по ключу-логину
                {
                    login = new HttpCookie("login", TextBox1.Text.Trim());
                    sign  = new HttpCookie("sign", SignGenerator.GetSign(TextBox1.Text.Trim() + "bytepp"));
                    metka = new HttpCookie("authorize", "authorize");

                    SqlCommand getid = new SqlCommand("select [IDKL] from [MARI].[KLIENTI] klient join[MARI].[Login] userauth on userauth.[Id] = klient.[IDKL] where userauth.[Login] = @login", conn);
                    getid.CommandType = CommandType.Text;
                    getid.Parameters.AddWithValue("login", TextBox1.Text.Trim());
                    getid.ExecuteNonQuery();

                    HttpCookie id = null;

                    SqlDataReader reader = getid.ExecuteReader();
                    while (reader.Read())
                    {
                        id = new HttpCookie("id", Convert.ToString(reader.GetValue(0)));
                    }
                    reader.Close();

                    Response.Cookies.Add(login); //добавляем в коллекцию кукисов свои
                    Response.Cookies.Add(sign);
                    Response.Cookies.Add(metka);
                    Response.Cookies.Add(id);

                    Response.Redirect("UserPage.aspx"); //передаем на след. страницу кукисы
                }
            }
            catch { }

            try {
                if (TextBox2.Text.Trim() == db_trener[TextBox1.Text.Trim()])
                {
                    login = new HttpCookie("login", TextBox1.Text.Trim());
                    sign  = new HttpCookie("sign", SignGenerator.GetSign(TextBox1.Text.Trim() + "bytepp"));
                    metka = new HttpCookie("authorize", "authorize");

                    SqlCommand getid = new SqlCommand("select trener.[IDTRENER] from [MARI].[TRENERI] trener join[MARI].[LogTren] trenauth on trenauth.[IDTRENER] = trener.[IDTRENER] where trenauth.[Login] = @login", conn);
                    getid.CommandType = CommandType.Text;
                    getid.Parameters.AddWithValue("login", TextBox1.Text.Trim());
                    getid.ExecuteNonQuery();

                    HttpCookie idtren = null;

                    SqlDataReader reader = getid.ExecuteReader();
                    while (reader.Read())
                    {
                        idtren = new HttpCookie("idtren", Convert.ToString(reader.GetValue(0)));
                    }
                    reader.Close();

                    Response.Cookies.Add(login); //добавляем в коллекцию кукисов свои
                    Response.Cookies.Add(sign);
                    Response.Cookies.Add(metka);
                    Response.Cookies.Add(idtren);

                    Response.Redirect("TrenerPage.aspx"); //передаем на след. страницу кукисы
                }
            }
            catch { }
        }