Authorization.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using System.Windows.Controls;
  9. using System.Windows.Data;
  10. using System.Windows.Documents;
  11. using System.Windows.Input;
  12. using System.Windows.Media;
  13. using System.Windows.Media.Imaging;
  14. using System.Windows.Navigation;
  15. using System.Windows.Shapes;
  16. namespace SneakersSkakunov
  17. {
  18. /// <summary>
  19. /// Логика взаимодействия для Authorization.xaml
  20. /// </summary>
  21. public partial class Authorization : Page
  22. {
  23. public Authorization()
  24. {
  25. InitializeComponent();
  26. }
  27. public void GoReg_Click(object sender, RoutedEventArgs e)
  28. {
  29. MainFrame.mframe.Navigate(new Registration());
  30. }
  31. private void Enter_Click(object sender, RoutedEventArgs e)
  32. {
  33. string CurPass = Pass.Password;
  34. using (SHA256 hash = SHA256.Create())
  35. {
  36. CurPass = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(CurPass))).Replace("-", "");
  37. }
  38. using (Sniker DB = new Sniker())
  39. {
  40. Users user = DB.Users.FirstOrDefault(x => x.Login == Login.Text && x.Password == CurPass);
  41. if (user != null)
  42. {
  43. switch (user.id_Role)
  44. {
  45. case 1:
  46. MainFrame.mframe.Navigate(new AdminPage());
  47. break;
  48. case 2:
  49. MainFrame.mframe.Navigate(new UserPage());
  50. break;
  51. default:
  52. MessageBox.Show("Вас не существует");
  53. break;
  54. }
  55. }
  56. else
  57. {
  58. MessageBox.Show("Вас не существует");
  59. }
  60. }
  61. }
  62. }
  63. }