forked from michael112/ForeignLanguageSchool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PasswordRecovery.aspx.cs
69 lines (62 loc) · 2.33 KB
/
PasswordRecovery.aspx.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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class PasswordRecovery : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
private class UserItemToRecover {
private int id;
internal UserItemToRecover(int id) {
this.id = id;
}
internal int getId() {
return this.id;
}
}
private UserItemToRecover LoginAndMailValidation(String seekingLogin, String seekingMail)
{
DataClassesDataContext d = new DataClassesDataContext();
var query = from u in d.Users where ((u.Login == seekingLogin) && (u.E_mail == seekingMail)) select u;
bool notEmpty = query.Any();
UserItemToRecover result;
if( notEmpty ) {
result = new UserItemToRecover(query.First().UserID);
}
else {
result = null;
}
d.Dispose();
return result;
}
private String SendPasswordToDatabase(String PasswordSalt, String PasswordHash, UserItemToRecover ValidationItem)
{
return "UPDATE Users SET PasswordSalt = '" + PasswordSalt + "', PasswordHash='" + PasswordHash + "' WHERE UserID = " + ValidationItem.getId() + ";";
}
protected void Button1_Click(object sender, EventArgs e)
{
UserItemToRecover ValidationItem = LoginAndMailValidation(TextBox1.Text, TextBox2.Text);
if( ValidationItem != null ) {
String newPassword = StringGen.GenString();
PasswordSaltAndHash sah = new PasswordSaltAndHash(newPassword);
String query = SendPasswordToDatabase(sah.getPasswordSalt(), sah.getPasswordHash(), ValidationItem);
try
{
SQLConnector.ProcessQuery(query);
Panel1.Visible = false;
Panel2.Visible = true;
Label1.Text = "<p class=\"center\">Hasło zostało zmienione pomyślnie. Nowe hasło brzmi: " + newPassword + "</p>";
}
catch (System.Data.SqlClient.SqlException ex)
{
Panel1.Visible = false;
Panel2.Visible = true;
Label1.Text = "<p class=\"center\">Baza wygenerowała następującego errora: " + ex.Message + "</p>";
}
}
}
}