Skip to content

Commit 212db57

Browse files
committed
login completed, added the encryption class
1 parent 0164986 commit 212db57

File tree

8 files changed

+242
-54
lines changed

8 files changed

+242
-54
lines changed

Library_Management_System_v0.1/Library_Management_System_v0.1/Home.Designer.cs

Lines changed: 31 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Library_Management_System_v0.1/Library_Management_System_v0.1/Home.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,13 @@ public Home()
1717
InitializeComponent();
1818
}
1919

20+
public Home(String userType)
21+
{
22+
InitializeComponent();
23+
buttonRegNewBook.Hide();
24+
buttonManageBooks.Hide();
25+
}
26+
2027
private void label2_Click(object sender, EventArgs e)
2128
{
2229

@@ -26,5 +33,10 @@ private void buttonSaveBook_Click(object sender, EventArgs e)
2633
{
2734

2835
}
36+
37+
private void Home_Load(object sender, EventArgs e)
38+
{
39+
40+
}
2941
}
3042
}

Library_Management_System_v0.1/Library_Management_System_v0.1/Library_Management_System_v0.1.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<Compile Include="Return_Books.Designer.cs">
147147
<DependentUpon>Return_Books.cs</DependentUpon>
148148
</Compile>
149+
<Compile Include="StringCipher.cs" />
149150
<EmbeddedResource Include="Add_New_Author.resx">
150151
<DependentUpon>Add_New_Author.cs</DependentUpon>
151152
</EmbeddedResource>

Library_Management_System_v0.1/Library_Management_System_v0.1/Login.Designer.cs

Lines changed: 24 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Library_Management_System_v0.1/Library_Management_System_v0.1/Login.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,70 @@ private void label3_Click(object sender, EventArgs e)
2525

2626
private void button1_Click(object sender, EventArgs e)
2727
{
28-
28+
//+++++++++ get input values from login form +++++++++//
29+
String email = textBoxEmail.Text;
30+
String password = textBoxPassword.Text;
31+
32+
//+++++++++ null & empty check for input values +++++++++//
33+
if ((email == null || email.Equals("")) && (password == null || password.Equals(""))) {
34+
MessageBox.Show("Email or Password Can't be Empty", "Authentication Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
35+
}
36+
else
37+
{
38+
String loginQuery = "SELECT * FROM user_login WHERE emailAddress = @email";
39+
String getUserRole = "SELECT * FROM user_role WHERE id = @userRoleId";
40+
MySqlConnection mySqlConnection = DataConnection.getDBConnection();
41+
mySqlConnection.Open();
42+
MySqlCommand command = new MySqlCommand(loginQuery, mySqlConnection);
43+
command.CommandText = loginQuery;
44+
command.Parameters.AddWithValue("@email", email);
45+
MySqlDataReader mySqlDataReader = command.ExecuteReader();
46+
47+
if (mySqlDataReader.HasRows)
48+
{
49+
while (mySqlDataReader.Read()) {
50+
String encPassword = mySqlDataReader.GetString("password");
51+
String decPassword = StringCipher.Decrypt(encPassword, LoginDetails.passwordKey);
52+
if (password.Equals(decPassword))
53+
{
54+
String userRoleId = mySqlDataReader.GetString("user_role_id");
55+
MySqlCommand commandGetUserRole = new MySqlCommand(getUserRole, mySqlConnection);
56+
commandGetUserRole.CommandText = getUserRole;
57+
commandGetUserRole.Parameters.AddWithValue("@userRoleId", userRoleId);
58+
mySqlDataReader.Close();
59+
MySqlDataReader mySqlDataReader2 = commandGetUserRole.ExecuteReader();
60+
if (mySqlDataReader2.HasRows)
61+
{
62+
mySqlDataReader2.Read();
63+
LoginDetails.userRole = mySqlDataReader2.GetString("name");
64+
if (LoginDetails.userRole.Equals("Administrative Librarian")) {
65+
Home home = new Home();
66+
home.Show();
67+
}
68+
else
69+
{
70+
Home home = new Home("librarian");
71+
home.Show();
72+
}
73+
this.Hide();
74+
75+
break;
76+
}
77+
else
78+
{
79+
MessageBox.Show("User type does not exists", "Authentication Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
80+
break;
81+
}
82+
}
83+
}
84+
}
85+
else {
86+
MessageBox.Show("Account does not exists", "Authentication Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
87+
}
88+
89+
mySqlConnection.Close();
90+
}
91+
2992
}
3093
}
3194
}

Library_Management_System_v0.1/Library_Management_System_v0.1/LoginDetails.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66

77
namespace Library_Management_System_v0._1
88
{
9+
910
public class LoginDetails
1011
{
1112
public static String userProfileID = "2";
1213
public static String userLoginHistoryID = "5";
14+
public static String userRole = "";
15+
public static String passwordKey = "123";
1316
}
1417
}

Library_Management_System_v0.1/Library_Management_System_v0.1/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ static void Main()
1616
{
1717
Application.EnableVisualStyles();
1818
Application.SetCompatibleTextRenderingDefault(false);
19-
Application.Run(new Register_new_books());
19+
Application.Run(new Login());
2020
}
2121
}
2222
}

0 commit comments

Comments
 (0)