Ejemplo n.º 1
0
 protected void btnRegister_Click(object sender, EventArgs e)
 {
     Cripter cr = new Cripter();
     string lg = tbNewLogin.Text;
     int pwdLength = tbNewPassword.Text.Length;
     int lgLength = lg.Length;
     if ((lgLength >= 1) & (pwdLength >= 8))
     {
         string pwd = cr.CriptString(tbNewPassword.Text);
         string connectionString = WebConfigurationManager.ConnectionStrings["SCSDataBase"].ConnectionString;
         SqlConnection con = new SqlConnection(connectionString);
         try
         {
             con.Open();
             SqlCommand cmd = new SqlCommand("exec CheckExistLogin @lg", con);
             cmd.CommandType = CommandType.Text;
             cmd.Parameters.Add("@lg", lg);
             int cnt = (int)cmd.ExecuteScalar();
             if (cnt == 0)
             {
                 cmd.CommandType = CommandType.Text;
                 cmd.CommandText = "EXEC AddLogin @lg, @pwd, '0'";
                 cmd.Parameters.Add("@pwd", pwd);
                 cmd.ExecuteNonQuery();
                 con.Close();
                 Response.Redirect("Default.aspx");
             }
             else
             {
                 string msg = "Такой логин уже существует, попробуйте другой";
                 Response.Write(msg);
             }
         }
         catch (Exception err)
         {
             Response.Write(err.Message);
         }
         finally
         {
             con.Close();
         }
     }
     else
     {
         if (pwdLength <= 7)
             Response.Write("Пароль должен быть длиннее <BR>");
         if (lgLength == 0)
             Response.Write("Введите логин");
     }
 }
Ejemplo n.º 2
0
 protected void btEnter_Click(object sender, EventArgs e)
 {
     Cripter cr = new Cripter();
         string lg = tbLogin.Text;
         int pwdLength = tbPassword.Text.Length;
         int lgLength = lg.Length;
         if ((lgLength >= 1) & (pwdLength >= 8))
         {
             string pwd = cr.CriptString(tbPassword.Text);
             string connectionString = WebConfigurationManager.ConnectionStrings["SCSDataBase"].ConnectionString;
             SqlConnection con = new SqlConnection(connectionString);
             try
             {
                 con.Open();
                 SqlCommand cmd = new SqlCommand("exec isRightLoginAndPassword @lg, @pwd", con);
                 cmd.CommandType = CommandType.Text;
                 cmd.Parameters.Add("@lg", lg);
                 cmd.Parameters.Add("@pwd", pwd);
                 int cnt = (int)cmd.ExecuteScalar();
                 if (cnt == 1)
                 {
                     Response.Write("=) <BR>");
                     Session["SCSLogin"] = lg;
                     Session["SCSDate"] = DateTime.Now.AddMinutes(10);
                     Response.Redirect("Default.aspx");
                 }
                 else
                 {
                     string msg = "Такого логина не существует, вам надо зарегистрироваться";
                     Response.Write(msg);
                 }
             }
             catch (Exception err)
             {
                 Response.Write(err.Message);
             }
             finally
             {
                 con.Close();
             }
         }
         else
         {
             if (pwdLength <= 7)
                 Response.Write("Пароль неверен <BR>");
             if (lgLength == 0)
                 Response.Write("Введите логин");
         }
 }
Ejemplo n.º 3
0
 protected void btOk_Click(object sender, EventArgs e)
 {
     Cripter cr = new Cripter();
     string lg = login;
     int pwdLength = tbOldPass.Text.Length;
     int lgLength = lg.Length;
     int newLength = tbNewPass.Text.Length;
     if ((lgLength >= 1) & (pwdLength >= 8) & (newLength >= 8))
     {
         string pwd = cr.CriptString(tbOldPass.Text);
         string newpass = cr.CriptString(tbNewPass.Text);
         string connectionString = WebConfigurationManager.ConnectionStrings["SCSDataBase"].ConnectionString;
         SqlConnection con = new SqlConnection(connectionString);
         try
         {
             con.Open();
             SqlCommand cmd = new SqlCommand("SELECT COUNT(LOGIN) AS cnt FROM LOGINS WHERE (Login=@lg)and(Cripted=@pwd)", con);
             cmd.CommandType = CommandType.Text;
             cmd.Parameters.Add("@lg", lg);
             cmd.Parameters.Add("@pwd", pwd);
             int cnt = (int)cmd.ExecuteScalar();
             if (cnt == 1)
             {
                 cmd.CommandText = "exec changepassword @lg, @np";
                 cmd.Parameters.Add("@np", newpass);
                 cmd.ExecuteNonQuery();
                 btCancel_Click(sender, e);
             }
             else
             {
                 string msg = "Пароль неверен";
                 Response.Write(msg);
             }
         }
         catch (Exception err)
         {
             Response.Write(err.Message);
         }
         finally
         {
             con.Close();
         }
     }
     else
     {
         if (pwdLength <= 7)
             Response.Write("Пароль неверен <BR>");
     }
 }