Reg.xaml.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace SSS
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для Reg.xaml
  21. /// </summary>
  22. public partial class Reg : Page
  23. {
  24. public Reg()
  25. {
  26. InitializeComponent();
  27. }
  28. public void Go1(object sender, RoutedEventArgs e)
  29. {
  30. MainFrame.Name1.Navigate(new Page1());
  31. }
  32. public void GoReg(object sender, RoutedEventArgs e)
  33. {
  34. if (!NaPerekrestkeNeGonit(Login.Text))
  35. { MessageBox.Show("Логин занят"); return; }
  36. if (!Tamoshna(Pass.Password))
  37. { MessageBox.Show("Пароль не соотвествует требованиям "); return; }
  38. string RegPass = Pass.Password;
  39. using (SHA256 hash = SHA256.Create())
  40. {
  41. RegPass = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(RegPass))).Replace("-", "");
  42. }
  43. int Pol;
  44. if (M.IsChecked == true) { Pol = 1; } else { Pol = 2; }
  45. Client client = new Client()
  46. {
  47. Login = Login.Text,
  48. Password = RegPass,
  49. Name = Name.Text,
  50. Surname = Surname.Text,
  51. Patronymic = Patronymic.Text,
  52. BirthDate = DataR.SelectedDate,
  53. id_Gender = Pol,
  54. id_Role = 2
  55. };
  56. using (Entities SSS = new Entities())
  57. {
  58. SSS.Client.Add(client);
  59. SSS.SaveChanges();
  60. }
  61. MessageBox.Show("Сохранено");
  62. }
  63. public bool NaPerekrestkeNeGonit(string Login)
  64. {
  65. using (Entities SSS = new Entities())
  66. {
  67. foreach (Client client in SSS.Client)
  68. {
  69. if (client.Login == Login)
  70. {
  71. return false;
  72. }
  73. }
  74. return true;
  75. }
  76. }
  77. public bool Tamoshna(string Password)
  78. {
  79. Regex Proverka = new Regex("(?=.*[A-Z])(?=.*[a-z]){3,}(?=.*[0-9]){2,}(?=.*[!@#$%^&&*()_])[A-Za-z0-9!@#$%^&*()_]{8,}");
  80. if (Proverka.IsMatch(Password)) { return true; } else { return false; }
  81. }
  82. private void Surname_TextChanged(object sender, TextChangedEventArgs e)
  83. {
  84. }
  85. private void Patronymic_TextChanged(object sender, TextChangedEventArgs e)
  86. {
  87. }
  88. }
  89. }