protected async void Page_Load(object sender, EventArgs e) { HttpCookie login = Request.Cookies["login"]; HttpCookie sign = Request.Cookies["sign"]; if (login != null && sign != null) { if (sign.Value == SignGenerator.GetSign(login.Value + "lasex")) { string connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString; sqlConnection = new SqlConnection(connectionString); await sqlConnection.OpenAsync(); return; } } Response.Redirect("Login.aspx", false); }
protected async void OnClick(object sender, EventArgs e) { Dictionary <string, User> db = new Dictionary <string, User>(); SqlCommand getUsersCredCmd = new SqlCommand("SELECT [Login], [Password], [Permission] FROM [Users]", sqlConnection); SqlDataReader sqlReader = null; try { sqlReader = await getUsersCredCmd.ExecuteReaderAsync(); while (await sqlReader.ReadAsync()) { db.Add(Convert.ToString(sqlReader["Login"].ToString()), new User(Convert.ToString(sqlReader["Password"].ToString()), Convert.ToString(sqlReader["Permission"].ToString()))); } } catch { } finally { sqlReader?.Close(); } if (TextBox2.Text == db[TextBox1.Text].password) { HttpCookie login = new HttpCookie("login", TextBox1.Text); HttpCookie sign = new HttpCookie("sign", SignGenerator.GetSign(TextBox1.Text + "lasex")); HttpCookie permission = new HttpCookie("permission", db[TextBox1.Text].permission); Response.Cookies.Add(login); Response.Cookies.Add(sign); Response.Cookies.Add(permission); Response.Redirect("index.aspx", false); } }
protected void Page_Load(object sender, EventArgs e) { HttpCookie login = Request.Cookies["login"]; HttpCookie sign = Request.Cookies["sign"]; HttpCookie permission = Request.Cookies["permission"]; if (login != null && sign != null) { if (sign.Value == SignGenerator.GetSign(login.Value + "lasex")) { if (login.Value != "admin") { Button7.Enabled = false; } try { string str = permission.Value; int count = 0; foreach (char ch in str) { string s = ch.ToString(); switch (count) { case 0: if (int.Parse(s) == 0) { Button1.Enabled = false; } break; case 1: if (int.Parse(s) == 0) { Button2.Enabled = false; } break; case 2: if (int.Parse(s) == 0) { Button3.Enabled = false; } break; case 3: if (int.Parse(s) == 0) { Button4.Enabled = false; } break; case 4: if (int.Parse(s) == 0) { Button5.Enabled = false; } break; } ++count; } } catch { } Label1.Text = "Ваш логин: " + login.Value; return; } } Response.Redirect("Login.aspx"); }