示例#1
0
        protected void fillValues(int id)
        {
            Benutzer b = getUser(id);

            BenutzerID.Text = b.BenutzerID.ToString();
            Vorname.Text    = b.Vorname;
            Nachname.Text   = b.Nachname;
            Passwort.Text   = b.Passwort;
            Email.Text      = b.Email;
            Klasse.Text     = b.Klasse;
            RollenID.Text   = b.RollenID.ToString();
        }
示例#2
0
        public static Benutzer getBenutzer(int id)
        {
            Benutzer b = new Benutzer();

            string connectionString = @"data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\SchulplanerDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"";

            //
            // In a using statement, acquire the SqlConnection as a resource.
            //
            using (SqlConnection con = new SqlConnection(connectionString))
            {
                //
                // Open the SqlConnection.
                //
                con.Open();
                //
                // The following code uses an SqlCommand based on the SqlConnection.
                //
                using (SqlCommand command = new SqlCommand("SELECT * FROM Benutzer WHERE BenutzerID=" + id, con))
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            // test.Text = reader.GetString(1);

                            Benutzer benutzer = new Benutzer();
                            try
                            {
                                benutzer.BenutzerID = reader.GetInt32(0);
                                benutzer.Vorname    = reader.GetString(1).ToString();
                                benutzer.Nachname   = reader.GetString(2);
                                benutzer.Passwort   = reader.GetString(3);
                                benutzer.Email      = reader.GetString(4);
                                benutzer.Klasse     = reader.GetString(5);
                                benutzer.RollenID   = reader.GetInt32(6);
                            }
                            catch (Exception e)
                            {
                                // test.Text = e.ToString();
                            }

                            return(benutzer);
                        }
                    }
                return(null);
            }
        }
示例#3
0
        protected void Log(object sender, EventArgs e)
        {
            String text = loginPass.Text;

            byte[]        bytes      = Encoding.UTF8.GetBytes(text);
            SHA256Managed hashstring = new SHA256Managed();

            byte[] hash       = hashstring.ComputeHash(bytes);
            string hashString = string.Empty;

            foreach (byte x in hash)
            {
                hashString += String.Format("{0:x2}", x);
            }


            String[] PW_and_ID = getPW(loginName.Text);

            if (hashString.Equals(PW_and_ID[0]))
            {
                test.Text = "eingeloggt";

                FormsAuthentication.SetAuthCookie(PW_and_ID[1], true); // Im AuthCookie die ID des Users speichern

                // HttpCookie aCookie = new HttpCookie("userName");
                Benutzer b = getUser.getBenutzer(Int32.Parse(PW_and_ID[1]));
                // aCookie.Value = "Hallo"; // b.Vorname + " ich bi so en idiot " + b.Nachname;
                // aCookie.Expires = DateTime.Now.AddDays(1);
                // Response.Cookies.Add(aCookie);

                Response.Cookies["userName"].Value   = b.Vorname + " " + b.Nachname;
                Response.Cookies["userName"].Expires = DateTime.Now.AddDays(1);

                test.Text = PW_and_ID[1];

                Response.Redirect("~/");
            }
            else
            {
                test.Text = "Falsches Passwort oder falscher Benutzername";
            }
        }