ASP.NET Page /UserLogin/CompletePasswordReset.aspx.cs (C#)
1: using System;  
2: using System.Data;  
3: using System.Configuration;  
4: using System.Collections;  
5: using System.Web;  
6: using System.Web.Security;  
7: using System.Web.UI;  
8: using System.Web.UI.WebControls;  
9: using System.Web.UI.HtmlControls;  
10: using System.Security;  
11: using QuizNetOnline.Logic;  
12:   
13: public partial class CompletePasswordReset : QuiznetOnline.Web.UI.BusinessClasses.BasePage  
14: {  
15:     protected override void Page_Load(object sender, EventArgs e)  
16:     {  
17:         if (!IsPostBack)  
18:         {  
19:             base.Page_Load(sender, e);  
20:   
21:             try  
22:             {  
23:                 Master.ShowHideMenu(false);  
24:                 ParseAndValidateKey();  
25:             }  
26:             catch (Exception)  
27:             {  
28:             }  
29:         }  
30:   
31:         if (User.Identity.IsAuthenticated)  
32:         {  
33:             Master.LogOut(false);  
34:         }  
35:     }  
36:   
37:     protected void ParseAndValidateKey()  
38:     {  
39:         // Get the encrypted string from the query string  
40:         string encrypted = Request.QueryString["k"] == null ? string.Empty : Request.QueryString["k"];  
41:         if (encrypted.Length == 0)  
42:         {  
43:             Master.DisplayMessage(HttpContext.GetGlobalResourceObject("Messages", "KeyIsNotValid").ToString(),true);  
44:         }  
45:         else  
46:         {  
47:             // Get the decrypted value  
48:             string decrypted = Crypto.Decrypt(encrypted, new Crypto());  
49:   
50:             // Parse the decrypted values  
51:             string[] delim = new string[1] { "---" };  
52:             string[] p = decrypted.Split(delim, StringSplitOptions.None);  
53:             if (p.Length != 2)  
54:             {  
55:                 // Could be tampering  
56:                 throw new SecurityException("Incorrect number of expected arguments.");  
57:             }  
58:             else  
59:             {  
60:                 if (string.IsNullOrEmpty(p[0]))  
61:                 {  
62:                     // Missing argument #2, could be tampering  
63:                     throw new SecurityException("Missing key argument 1");  
64:                 }  
65:                 else if (string.IsNullOrEmpty(p[1]))  
66:                 {  
67:                     // Missing argument #2, could be tampering  
68:                     throw new SecurityException("Missing key argument 2");  
69:                 }  
70:                 else  
71:                 {  
72:   
73:                     // Set the user name to that provided by the key  
74:                     ChangePasswordCtrl.UserName = p[0];  
75:                     p[0] = string.Empty;  
76:   
77:                     // Save the encrypted password for future use  
78:                     ViewState["p"] = p[1];  
79:                     p[1] = string.Empty;  
80:                 }  
81:             }  
82:         }  
83:     }  
84:   
85:     protected void ChangePasswordCtrl_ChangingPassword(object sender, LoginCancelEventArgs e)  
86:     {  
87:         // Set the current password to the one provided in the key  
88:         if (ViewState["p"] != null)  
89:         {  
90:             TextBox currentPasswordTextBox = (TextBox)ChangePasswordCtrl.ChangePasswordTemplateContainer.FindControl("CurrentPassword");  
91:             currentPasswordTextBox.Text = Crypto.Decrypt(ViewState["p"].ToString(), new Crypto());  
92:         }  
93:     }  
94: }    

.NET Documentation Tool is © 2002 - 2009 Winnersh Triangle Web Solutions Limited.