65 lines
1.6 KiB
C#
65 lines
1.6 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Drawing;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using Diplom_O.DataBase;
|
||
using System.Security.Cryptography;
|
||
|
||
namespace Diplom_O
|
||
{
|
||
public partial class LoginForm : Form
|
||
{
|
||
public bool isCanceled = false;
|
||
public LoginForm()
|
||
{
|
||
InitializeComponent();
|
||
try
|
||
{
|
||
loginBox.Items.Clear();
|
||
var userList = FuncDB.UserList();
|
||
foreach (var usr in userList)
|
||
loginBox.Items.Add(usr.Login);
|
||
if (loginBox.Items.Count > 0)
|
||
loginBox.SelectedIndex = 0;
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
this.ShowError(errorLabel, e.Message);
|
||
workButton.Enabled = false;
|
||
}
|
||
}
|
||
|
||
private void workButton_Click(object sender, EventArgs e)
|
||
{
|
||
try
|
||
{
|
||
var _user = FuncDB.UserGetByLogin((string)loginBox.Text);
|
||
if (_user == null)
|
||
throw new Exception("Пользователя не существует.");
|
||
if (_user.Pass != textBox1.Text)
|
||
throw new Exception("Не верный пароль.");
|
||
byte[] pass_bytes = Encoding.ASCII.GetBytes(textBox1.Text);
|
||
var pass_hash_bytes = new MD5CryptoServiceProvider().ComputeHash(pass_bytes);
|
||
_user.Pass = Encoding.ASCII.GetString(pass_hash_bytes);
|
||
this.SetUser(_user);
|
||
this.SetNextForm(_user.Default);
|
||
this.Close();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
this.ShowError(errorLabel, ex.Message);
|
||
}
|
||
}
|
||
private void canceledButton_Click(object sender, EventArgs e)
|
||
{
|
||
isCanceled = true;
|
||
this.Close();
|
||
}
|
||
}
|
||
}
|