public void RegisterMethod() { HIF3eLernzielDBEntities db = new HIF3eLernzielDBEntities(); if (PassWord == null || UserName == null || Schule == null) { Response = "Please fill out all Fields!"; } else { if (PassWord.Length > 5 && UserName.Length > 2) { string hashPassWord = HashCalculator.ComputeSha256Hash(PassWord); Benutzer b = new Benutzer { Pwd = hashPassWord, Username = UserName, LoggedIn = true, Schule = Schule }; db.Benutzers.Add(b); db.SaveChanges(); MainWindow newWindow = new MainWindow(); newWindow.ShowDialog(); CloseAction(); } else { Response = "Username min. 3 Letters, Pwd 6."; } } }
private bool validatePassword() { HIF3eLernzielDBEntities db = new HIF3eLernzielDBEntities(); if (UserName == null || PassWord == null) { Response = "Please enter both values!"; return(false); } Benutzer User = (from a in db.Benutzers where a.Username == UserName select a).FirstOrDefault <Benutzer>(); if (User == null) { Console.WriteLine("Non existing user"); Response = "This User does not exist"; return(false); } if (User.Username == UserName && User.Pwd == HashCalculator.ComputeSha256Hash(PassWord)) { User.LoggedIn = true; db.SaveChanges(); return(true); } else { Response = "Password not correct"; return(false); } }