-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccessUserDB.cs
60 lines (49 loc) · 1.93 KB
/
AccessUserDB.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System.Windows;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using System;
namespace dbCon2
{
class AccessUserDB
{
public User TryToFindUser(string userName, string password)
{
try
{
ConnectionSettings connectionSettings = new ConnectionSettings();
connectionSettings.ConnectionSet();
using (MySqlConnection connection = new MySqlConnection(ConnectionSettings.ConectionVal()))
{
User user = new User();
string passwordFromDB = "";
MySqlCommand command = connection.CreateCommand();
command.CommandText = $"SELECT * FROM users WHERE User_Name='{ userName }' AND User_Password='{ password }';";
connection.Open();
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
user.Userset(reader["User_Name"].ToString(), reader["User_Rank"].ToString(), reader["User_ID"].ToString(), false);
passwordFromDB = reader["User_Password"].ToString();
};
connection.Close();
if(user.UserNameDB == userName && passwordFromDB == password)
{
return user;
}
else
{
return null;
}
}
}
catch(Exception e)
{
MessageBox.Show("Can't connect! Login in as default admin and configurate connection.");
return null;
}
}
}
}