Advertisement
Guest User

Untitled

a guest
Dec 8th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ASP 3.77 KB | None | 0 0
  1. @helper Login()
  2. {
  3. // per Get übergebene login und passwort werden zwischengespeichert
  4. // (falls überhaupt was übergeben wurde, ansonsten kommt da automatisch null rein)
  5.     string user = Request.Params.Get("login");
  6.     string passwort = Request.Params.Get("passwort");
  7.  
  8.     // wurde der abmeldeknopf gedrückt, wird die session auf null gesetzt
  9.     if (Request.Params.Get("abmelden") == "true")
  10.     {
  11.         user = null;
  12.         passwort = null;
  13.  
  14.         Session["user"] = null;
  15.         Session["role"] = null;
  16.     }
  17.  
  18.  
  19.     // wurde login und passwort übergeben (also nicht null), dann wird versucht eine connection und eine query zum server aufgebaut zu werden
  20.     if (user != null && passwort != null)
  21.     {
  22.         using (MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString))
  23.         {
  24.             try
  25.             {
  26.                 con.Open();
  27.                 using (MySqlCommand command = new MySqlCommand("", con))
  28.                 {
  29.                     // die query fragt ab ob ein benutzer mit dem übergebenen username gefunden wird
  30.                     command.CommandText = "CALL rolle((SELECT Nummer FROM Nutzer WHERE Nutzername = '" + user + "') );";
  31.  
  32.                     var r = command.ExecuteReader();
  33.  
  34.                     r.Read();
  35.  
  36.                     // gibt die query eine antwort mit dem Spaltennamen "Rolle" zurück, dann wird eine Session gesetzt
  37.                     // hier kommt noch eine passwortabfrage rein
  38.                     // TODO  && PasswordStorage.VerifyPassword(passwort, r["Hash"].ToString())
  39.                     if (r["Rolle"] != null)
  40.                     {
  41.                         //if Daten korrekt, dann session
  42.                         Session["user"] = user;
  43.                         Session["role"] = r["Rolle"];
  44.  
  45.  
  46.  
  47.                         <text>
  48.                             Benutzer gefunden, dieser ist @r["Rolle"]
  49.                         </text>
  50.                     }
  51.                     else
  52.                     {
  53.                         <text>Passwort falsch</text>
  54.                     }
  55.                 }
  56.             }
  57.             catch (Exception ex)
  58.             {
  59.                 // TODO  && PasswordStorage.VerifyPassword(passwort, r["Hash"].ToString())
  60.  
  61.                 <text> Falsche Daten</text>
  62.             }
  63.         }
  64.     }
  65.  
  66.     // sind alle fälle oben fehlgeschlagen, also wenn eine Session noch nicht gesetzt wurde, dann wird der Login aufgebaut
  67.     if (string.IsNullOrEmpty(Session["user"] as string))
  68.     {
  69.         <form method="post" action="#" target="_self">
  70.             <div class="form-group">
  71.                 <fieldset>
  72.                     <legend>Login</legend>
  73.  
  74.                     <div class="row" id="mylogin">
  75.  
  76.                         <label class="sr-only" for="login">Benutzer</label>
  77.                         <input name="login" id="login" type="tel" class="form-control" placeholder="Benutzer" />
  78.                         <label class="sr-only" for="pass">Passwort</label>
  79.                         <input name="passwort" id="pass" type="password" class="form-control" placeholder="********" />
  80.                     </div>
  81.                     <button type="submit" class="btn btn-block">Anmelden</button>
  82.  
  83.                 </fieldset>
  84.             </div>
  85.  
  86.         </form>
  87.     }
  88.  
  89.     // ansonsten wird der abmeldeknopf angezeigt
  90.     else
  91.     {
  92.         <form method="post" action="#" target="_self">
  93.             <div class="form-group">
  94.  
  95.                 <div class="row" id="mylogin">
  96.                     <input class="form-control" type="hidden" name="abmelden" value="true" />
  97.                 </div>
  98.                 <button type="submit" class="btn btn-block">Abmelden</button>
  99.             </div>
  100.         </form>
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement