be3d336ba94aaef2423abed1e88e43f743ee02e3
Izenda-Guides.md
| ... | ... | @@ -1,2 +1,51 @@ |
| 1 | -#Izenda Guides |
|
| 1 | +#Authentication Function |
|
| 2 | 2 | |
| 3 | +[[_TOC_]] |
|
| 4 | + |
|
| 5 | +##About |
|
| 6 | + |
|
| 7 | +This is a simple authentication function you can place in your Login page (Login.aspx in the default starter kit). |
|
| 8 | + |
|
| 9 | +Normally, logins should be pulled from the database, active directory, or whatever system your organization uses for storing user info. We also support using your company's existing login page in place of our example login page. If nothing is available, here is a simple method to provide basic authentication. Also included is the callback function used by **btnLogin**'s "OnClick" property. |
|
| 10 | + |
|
| 11 | +Bool AuthenticateUser(string userName, string password, out bool isAdmin) |
|
| 12 | +{ |
|
| 13 | + System.Collections.Hashtable Passwords = new System.Collections.Hashtable(); |
|
| 14 | + System.Collections.ArrayList Admins = new System.Collections.ArrayList(); |
|
| 15 | + |
|
| 16 | + Passwords["Bob"]="password"; |
|
| 17 | + Passwords["Steve"]="password"; |
|
| 18 | + Passwords["Stacey"]="password"; |
|
| 19 | + Passwords["Kim"]="password"; |
|
| 20 | + |
|
| 21 | + Admins.Add("Bob"); |
|
| 22 | + Admins.Add("Steve"); |
|
| 23 | + |
|
| 24 | + if(Passwords[userName].Equals(password)) |
|
| 25 | + { |
|
| 26 | + isAdmin = Admins.Contains(userName); |
|
| 27 | + return true; |
|
| 28 | + } |
|
| 29 | + |
|
| 30 | + // Could not authenticate |
|
| 31 | + return false; |
|
| 32 | +} |
|
| 33 | +void btnLogin_Click(object sender, EventArgs args) |
|
| 34 | +{ |
|
| 35 | + loginValidator.IsValid = true; |
|
| 36 | + bool isAdmin; |
|
| 37 | + if (AuthenticateUser(userNameTextbox.Text, userPassword.Value, out isAdmin)) { |
|
| 38 | + HttpContext.Current.Session["UserName"] = userNameTextbox.Text; |
|
| 39 | + if (isAdmin) |
|
| 40 | + HttpContext.Current.Session["Role"] = "Admin"; |
|
| 41 | + else |
|
| 42 | + HttpContext.Current.Session["Role"] = "RegularUser"; |
|
| 43 | + global_asax.CustomAdHocConfig.InitializeReporting(); |
|
| 44 | + Response.Redirect("ReportList.aspx"); |
|
| 45 | + Page.Title = "Izenda - " + AdHocSettings.CurrentUserName; |
|
| 46 | + //FormsAuthentication.RedirectFromLoginPage(userNameTextbox.Text, false); |
|
| 47 | + return; |
|
| 48 | + } |
|
| 49 | + else |
|
| 50 | + loginValidator.IsValid = false; |
|
| 51 | +} |
|
| ... | ... | \ No newline at end of file |