Question : ASP.NET 3.5 login page (C#)

Hi experts

I'm trying to create a login page that will authenticate users that are in a SQL Server 2005 database. I'm creating the login page in Visual Studio 2008 Professional Edition (Trial Version).

The login page is fine, it's the class that is authenticating the user that I'm having problems with. It has given me errors with my case statement amongst other things and I'm not sure how to correct it.
Any help would be greatly appreciated.

Thanks
Code Snippet:
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:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
Login page:
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="SmartLearner.Login" %>
 

 


    Secure Site    
        
        
        
      
      
        
          
    
E-mail:
Password:
 
Class: using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; namespace SmartLearner { public class CCommonDB: CSql {public CCommonDB() : base() { } public string AuthenticateUser( System.Web.SessionState.HttpSessionState objSession, // Session Variable System.Web.HttpResponse objResponse, // Response Variable string email, // Login string password, // Password bool bPersist // Persist login ) { int nLoginID = 0; int nLoginType = 0; // Log the user in Login(email, password, ref nLoginID, ref nLoginType); if(nLoginID != 0) // Success { // Log the user in System.Web.Security.FormsAuthentication.SetAuthCookie(nLoginID.ToString(), bPersist); // Set the session varaibles objSession["loginID"] = nLoginID.ToString(); objSession["loginType"] = nLoginType.ToString(); // Set cookie information incase they made it persistant System.Web.HttpCookie wrapperCookie = new System.Web.HttpCookie("wrapper"); wrapperCookie.Value = objSession["wrapper"].ToString(); wrapperCookie.Expires = DateTime.Now.AddDays(30); System.Web.HttpCookie lgnTypeCookie = new System.Web.HttpCookie("loginType"); lgnTypeCookie.Value = objSession["loginType"].ToString(); lgnTypeCookie.Expires = DateTime.Now.AddDays(30); // Add the cookie to the response objResponse.Cookies.Add(wrapperCookie); objResponse.Cookies.Add(lgnTypeCookie); return "/default.aspx"; } case 1: // Admin Login { return "/Admin.aspx"; } case 2: // Staff Login { return "/Staff.aspx"; } default: { return string.Empty; } } } else { return string.Empty; } } /// /// Verifies the login and password that were given /// /// the login /// the password /// returns the login id /// returns the login type public void Login(string email, string password, ref int nLoginID, ref int nLoginType) { ResetSql(); DataSet ds = new DataSet(); // Set our parameters SqlParameter paramLogin = new SqlParameter("@username", SqlDbType.VarChar, 100); paramLogin.Value = email; SqlParameter paramPassword = new SqlParameter("@password", SqlDbType.VarChar, 20); paramPassword.Value = password; Command.CommandType = CommandType.StoredProcedure; Command.CommandText = "glbl_Login"; Command.Parameters.Add(paramLogin); Command.Parameters.Add(paramPassword); Adapter.TableMappings.Add("Table", "Login"); Adapter.SelectCommand = Command; Adapter.Fill(ds); if(ds.Tables.Count != 0) { DataRow row = ds.Tables[0].Rows[0]; // Get the login id and the login type nLoginID = Convert.ToInt32(row["Login_ID"].ToString()); nLoginType = Convert.ToInt32(row["Login_Type"].ToString()); } else { nLoginID = 0; nLoginType = 0; } } } } abstract public class CSql { private SqlConnection sqlConnection; // Connection string private SqlCommand sqlCommand; // Command private SqlDataAdapter sqlDataAdapter; // Data Adapter private DataSet sqlDataSet; // Data Set public CSql() { sqlConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]); sqlCommand = new SqlCommand(); sqlDataAdapter = new SqlDataAdapter(); sqlDataSet = new DataSet(); sqlCommand.Connection = sqlConnection; } /// /// Access to our sql command /// protected SqlCommand Command { get { return sqlCommand; } } /// /// Access to our data adapter /// protected SqlDataAdapter Adapter { get { return sqlDataAdapter; } } /// /// Makes sure that everything is clear and ready for a new query /// protected void ResetSql() { if(sqlCommand != null) { sqlCommand = new SqlCommand(); sqlCommand.Connection = sqlConnection; } if(sqlDataAdapter != null) sqlDataAdapter = new SqlDataAdapter(); if(sqlDataSet != null) sqlDataSet = new DataSet(); } /// /// Runs our command and returns the dataset /// /// the data set protected DataSet RunQuery() { sqlDataAdapter.SelectCommand = Command; sqlConnection.Open(); sqlConnection.Close(); sqlDataAdapter.Fill(sqlDataSet); return sqlDataSet; } } }

Answer : ASP.NET 3.5 login page (C#)

OhO you went way too far....
If you don't mind not using what you have right now and can go with other approaches...check this one first:
http://www.codedigest.com/Articles/ASPNET/112_Implementing_Forms_Authentication_in_ASPNet_20.aspx

Then look at the following videos they are great to start learning on setting up login mechanism:
http://www.asp.net/learn/security-videos/

FormsAuthentication and asp.net Membership/Roles provider will make your coding easy and efficient.
Random Solutions  
 
programming4us programming4us