-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbChangePassword.cs
84 lines (57 loc) · 1.9 KB
/
dbChangePassword.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Windows.Forms;
namespace login1
{
public class dbChangePassword
{
SqlConnection con;
public dbChangePassword()
{
//SqlConnection con;
dbConnection cn = new dbConnection();//Establishes a connection
con= cn.connect();//Establishes a connection
}
public bool passwordChangeCheck(string role, string oldPassword, string newPassword)
{
try
{
string strSQL1 = "Update login1 set password='" + newPassword + "' where password in( Select password From login1 where role='" + role + "'and password='" + oldPassword + "')";
string strSQL2 = "Select password From login1 where role='" + role + "'";
SqlCommand cmd1 = new SqlCommand(strSQL1, con);
SqlCommand cmd2 = new SqlCommand(strSQL2, con);
SqlDataReader rd2;
rd2 = cmd2.ExecuteReader();
while (rd2.Read())
{
if (oldPassword == rd2.GetString(rd2.GetOrdinal("password")))
{
rd2.Close();
cmd1.ExecuteNonQuery();
return true;
}
else
{
return false;
}
}
return false;
}
catch (Exception e)
{
MessageBox.Show("Password change failed!!Try ");
return false;
}
/*finally
{
dbConnection cn = new dbConnection();
// cn.disconnect(cn);
return false;
}*/
}
}
}