Authorization.xaml.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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.Media.Media3D;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. namespace MusicSmth
  18. {
  19. /// <summary>
  20. /// Логика взаимодействия для Auuhorization.xaml
  21. /// </summary>
  22. public partial class Authorization : Page
  23. {
  24. public Authorization()
  25. {
  26. InitializeComponent();
  27. }
  28. public void GoReg_Click(object sender, RoutedEventArgs e)
  29. {
  30. MainFrame.mframe.Navigate(new Registration());
  31. }
  32. private void Enter_Click(object sender, RoutedEventArgs e)
  33. {
  34. string CurPass = Pass.Password;
  35. using (SHA256 hash = SHA256.Create())
  36. {
  37. CurPass = BitConverter.ToString(hash.ComputeHash(Encoding.UTF8.GetBytes(CurPass))).Replace("-", "");
  38. }
  39. using (Music DB = new Music())
  40. {
  41. Users user = DB.Users.FirstOrDefault(x => x.Login == Login.Text && x.Password == CurPass);
  42. if (user != null)
  43. {
  44. switch (user.Role)
  45. {
  46. case 1:
  47. MainFrame.mframe.Navigate(new AdminPage(user.Id));
  48. break;
  49. case 2:
  50. MainFrame.mframe.Navigate(new UserPage(user.Id));
  51. break;
  52. default:
  53. MessageBox.Show("Вас не существует");
  54. break;
  55. }
  56. }
  57. else
  58. {
  59. MessageBox.Show("Вас не существует");
  60. }
  61. }
  62. }
  63. }
  64. }