private void loginClick(object sender, EventArgs e) { SHA256 sha256 = SHA256.Create(); string user = uzivJmenoTxtBx.Text; string pass = hesloTxtBx.Text; byte[] userByte = Encoding.UTF8.GetBytes(user); byte[] encryptedPass = sha256.ComputeHash(Encoding.UTF8.GetBytes(pass)); string path = Environment.CurrentDirectory + "\\Uzivatele" + "\\" + BitConverter.ToString(userByte).Replace("-", "").ToLower() + ".txt"; FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); if (!File.Exists(path)) { label6.Text = "Zadali jste špatné jméno nebo heslo"; label6.Show(); } if (uzivJmenoTxtBx.Text == "" || hesloTxtBx.Text == "") { if (uzivJmenoTxtBx.Text == "") { label4.Show(); label4.Text = "Zadejte uživatelské jméno"; } if (hesloTxtBx.Text == "") { label5.Show(); label5.Text = "Zadejte heslo"; } } fs.Close(); #region adminLogin if (user == "admin") { Regex rx = new Regex(@"(?<=pass: )\S+"); using (StreamReader sr = new StreamReader(path)) { //Regex rx = new Regex(@"(?<=pass: )\S+"); string line; while ((line = sr.ReadLine()) != null) { if (rx.IsMatch(line)) { if (Convert.ToString(rx.Match(line)) == BitConverter.ToString(encryptedPass).Replace("-", "").ToLower()) { AdminskyForm af = new AdminskyForm(); af.Show(); this.Hide(); } else { label6.Text = "Zadali jste spatne heslo!"; label7.Text = pass; label6.Show(); } } } } } #endregion bool zmenahesla = false; Regex rg = new Regex(@"(?<=pass: )\S+"); if (user != "" && pass != "") { if (File.Exists(path)) { string[] lines = File.ReadAllLines(path); for (int i = 0; i < lines.Length; i++) { if (!rg.IsMatch(lines[i]) /*lines[i].Contains("zmenahesla")*/) { zmenahesla = true; } } if (File.Exists(path) && zmenahesla == true) { zmenaHesla zh = new zmenaHesla(pass); zh.Show(); this.Hide(); } } } if (File.Exists(path) && user != "admin") { string password = ""; using (StreamReader sr = new StreamReader(path)) { Regex rx = new Regex(@"(?<=pass: )\S+"); string line; while ((line = sr.ReadLine()) != null) { if (rx.IsMatch(line)) { password = Convert.ToString(rx.Match(line)); label5.Text = password; } } label5.Text = password; label5.Show(); } if (BitConverter.ToString(encryptedPass).Replace("-", "").ToLower() == password) { using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(DateTime.Now); } this.Hide(); UzivatelskyForm uf = new UzivatelskyForm(); uf.Show(); } } fs.Close(); }
private void loginClick(object sender, EventArgs e) { SHA256 sha256 = SHA256.Create(); string user = uzivJmenoTxtBx.Text; string pass = hesloTxtBx.Text; byte[] userByte = Encoding.UTF8.GetBytes(user); byte[] encryptedPass = sha256.ComputeHash(Encoding.UTF8.GetBytes(pass)); string path = Environment.CurrentDirectory + "\\Uzivatele" + "\\" + BitConverter.ToString(userByte).Replace("-", "").ToLower() + ".txt"; if (uzivJmenoTxtBx.Text == "" || hesloTxtBx.Text == "") { if (uzivJmenoTxtBx.Text == "") { label4.Show(); label4.Text = "Zadejte uživatelské jméno"; } if (hesloTxtBx.Text == "") { label5.Show(); label5.Text = "Zadejte heslo"; } } if (user == "admin") { Regex rx = new Regex(@"(?<=pass: )\S+"); using (StreamReader sr = new StreamReader(path)) { //Regex rx = new Regex(@"(?<=pass: )\S+"); string line; string match; while ((line = sr.ReadLine()) != null) { if (rx.IsMatch(line)) { if (Convert.ToString(rx.Match(line)) == BitConverter.ToString(encryptedPass).Replace("-", "").ToLower()) { AdminskyForm af = new AdminskyForm(); this.Hide(); af.ShowDialog(); } } else { label6.Text = "Zadali jste spatne heslo!"; label7.Text = pass; label6.Show(); } } } } string misPass = ""; using (StreamReader sr = new StreamReader(path)) { Regex rx = new Regex(@"(?<=pass: )\S+"); string line; while ((line = sr.ReadLine()) != null) { if (rx.IsMatch(line)) { misPass = Convert.ToString(rx.Match(line)); } } } if (File.Exists(path) && (misPass == "")) { } //using (StreamReader sr = new StreamReader(path)) //{ //} if (File.Exists(path)) { string password = ""; using (StreamReader sr = new StreamReader(path)) { Regex rx = new Regex(@"(?<=pass: )\S+"); string line; while ((line = sr.ReadLine()) != null) { if (rx.IsMatch(line)) { password = Convert.ToString(rx.Match(line)); label5.Text = password; } } label5.Text = password; label5.Show(); } if (BitConverter.ToString(encryptedPass).Replace("-", "").ToLower() == password) { using (StreamWriter sw = File.AppendText(path)) { sw.WriteLine(DateTime.Now); } this.Hide(); UzivatelskyForm uf = new UzivatelskyForm(); uf.Show(); } } }