Guest User

prijava koda

a guest
Jun 8th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.89 KB | None | 0 0
  1. string connStr = ConfigurationManager.ConnectionStrings["sodnik_za_prekrskeConnectionString1"].ConnectionString;
  2.             SqlConnection conn = new SqlConnection(connStr);
  3.  
  4.             conn.Open();
  5.             SqlCommand userExists = new SqlCommand("select count(*) from uporabnik where username = '" + textBoxUsernameLogin.Text + "'", conn);
  6.             SqlCommand userData = new SqlCommand("select username, password from uporabnik where username = '" + textBoxUsernameLogin.Text + "'", conn);
  7.  
  8.             SqlCommand getUserType = new SqlCommand("select vrsta_uporabnika from uporabnik where username = '"+textBoxUsernameLogin.Text+"'", conn);
  9.             SqlCommand getIme = new SqlCommand("select ime from uporabnik where username = '" + textBoxUsernameLogin.Text + "'", conn);
  10.             SqlCommand getPriimek = new SqlCommand("select priimek from uporabnik where username = '" + textBoxUsernameLogin.Text + "'", conn);
  11.  
  12.             int obstaja = Convert.ToInt32(userExists.ExecuteScalar().ToString());
  13.             conn.Close();
  14.  
  15.            
  16.  
  17.             if (obstaja == 1)
  18.             {
  19.                 conn.Open();
  20.                 string userType = getUserType.ExecuteScalar().ToString();
  21.  
  22.  
  23.                 string checkPass = "select password from uporabnik where username='" + textBoxUsernameLogin.Text + "'";
  24.                
  25.  
  26.  
  27.                 SqlCommand passComm = new SqlCommand(checkPass, conn);
  28.                 string password = passComm.ExecuteScalar().ToString();
  29.  
  30.                 if (password == textBoxPasswordLogin.Text)
  31.                 {
  32.                     if(userType == "admin")
  33.                     {
  34.                         status_prijave.InnerText = "Prijava uspešna";
  35.                         Session["login"] = "admin";
  36.                         Session["ime"] = getIme.ExecuteScalar().ToString();
  37.                         Session["priimek"] = getPriimek.ExecuteScalar().ToString();
  38.                         conn.Close();
  39.                         Response.Redirect("orodja.aspx");
  40.                     }
  41.  
  42.                     if (userType == "user")
  43.                     {
  44.                         status_prijave.InnerText = "Prijava uspešna";
  45.                         Session["login"] = "user";
  46.                         Session["ime"] = getIme.ExecuteScalar().ToString();
  47.                         Session["priimek"] = getPriimek.ExecuteScalar().ToString();
  48.                         conn.Close();
  49.                         Response.Redirect("uporabnik.aspx");
  50.                     }
  51.                    
  52.                    
  53.                 }
  54.                 else
  55.                 {
  56.                     status_prijave.InnerText = "Napačno geslo";
  57.                     conn.Close();
  58.                 }
  59.             }
  60.             else
  61.             {
  62.                 status_prijave.InnerText = "Uporabnik ne obstaja";
  63.                 conn.Close();
  64.             }
  65.             conn.Close();
Add Comment
Please, Sign In to add comment