Ejemplo n.º 1
0
        protected void Button3_Click(object sender, EventArgs e)
        {
            if (TextBox2.Text == TextBox3.Text)
            {
                string connectionString =
                    WebConfigurationManager.ConnectionStrings["Salary"].ConnectionString;
                SqlConnection connection = new SqlConnection(connectionString);

                Login    = TextBox1.Text;
                Password = Encrypt_Service.Encrypt(TextBox2.Text);
                SqlCommand command = new SqlCommand($"INSERT INTO Users VALUES ('{Login}', '{Password}')", connection);
                using (connection)
                {
                    connection.Open();
                    try
                    {
                        var        res    = command.ExecuteNonQuery();
                        HttpCookie cookie = new HttpCookie("Login", Login);
                        Response.Cookies.Add(cookie);
                        Response.Redirect("Default.aspx");
                    }
                    catch (SqlException ex)
                    {
                        Label2.Text = "This login exist";
                    }
                }
            }
            else
            {
                Label2.Text = "Try again";
            }
        }
Ejemplo n.º 2
0
        protected void Button1_Click(object sender, EventArgs e)
        {
            string connectionString =
                WebConfigurationManager.ConnectionStrings["Salary"].ConnectionString;
            SqlConnection connection = new SqlConnection(connectionString);

            Login    = inputLogin.Text;
            Password = Encrypt_Service.Encrypt(inputPassword.Text);
            SqlCommand command = new SqlCommand($"select dbo.LogIn('{Login}', '{Password}')", connection);

            using (connection)
            {
                connection.Open();
                object res = command.ExecuteScalar();


                if (Convert.ToBoolean(res))
                {
                    HttpCookie cookie = new HttpCookie("Login", Login);
                    Response.Cookies.Add(cookie);
                    Response.Redirect("Default.aspx");
                }
                else
                {
                    Label1.Text      = "Try again";
                    Label1.ForeColor = Color.Red;
                }
            }
        }