-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginScreen.xaml.cs
105 lines (89 loc) · 2.75 KB
/
LoginScreen.xaml.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Auction
{
/// <summary>
/// Interaction logic for LoginScreen.xaml
/// </summary>
public partial class LoginScreen : Window
{
/**
* Initialize Components of the Login Screen
*/
public LoginScreen()
{
InitializeComponent();
}
/**
* Function to carry out the login process for the particular user
*/
private void ClickLogin_Submit(object sender, RoutedEventArgs e)
{
string username = txtLogin_Username.Text;
string pwd = txpLogin_Pwd.Password;
// Validate Username
if(username.Trim()=="")
{
string msg = "Please Enter Username";
Console.WriteLine(msg);
lblLogin_Message.Content = msg;
return;
}
// Validate Password
if (pwd.Trim() == "")
{
string msg = "Please Enter Password";
Console.WriteLine(msg);
lblLogin_Message.Content = msg;
return;
}
IList<Users> users = getUsers(username, pwd);
if(users==null || users.Count==0)
{
string msg = "Invalid Credentials";
Console.WriteLine(msg);
lblLogin_Message.Content = msg;
return;
}
Users user = users[0];
Console.WriteLine("Login Successfull:");
Console.WriteLine(user.toString());
// Create instance of the main window
MainWindow mainWindow = new MainWindow(user);
// Close the current login window
this.Close();
// Show the main window
mainWindow.Show();
}
/**
* Gets the user from collection with the given username and password
*
* Parameters:
* string:
* username
*
* string:
* pwd
*/
public IList<Users> getUsers(string username, string pwd)
{
// Create Query upon establishing connection with the Database
string query = "WHERE username='" + username + "' AND pwd=MD5('" + pwd + "') ";
return UsersTableData.getUsers(query);
}
}
}