473,468 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to

4 New Member
i've problem with login page.i need some guides or example coding to help me. i successfully create simple login page rite now n now i want adds some features based on accesslevel. i don't wanna using and i really don't know how to use roles based..so i really needs ur help..here my simple code..hope u can help me guys..

here my code:

Default.aspx
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="test._Default" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" >
  6. <head runat="server">
  7.     <title>Untitled Page</title>
  8.     <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
  9.     <meta name="CODE_LANGUAGE" content="C#">
  10.     <meta name="vs_defaultClientScript" content="JavaScript">
  11.     <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">       
  12. </head>
  13. <body>
  14.  
  15. <form id="frmlogin" method="post" runat="server">
  16.             <table id="mainTable" border="0">
  17.                 <tr>
  18.                     <td>
  19.                         <table class="t_border" id="loginTable" cellspacing="15" cellpadding="0">
  20.                         <tr>
  21.                             <td><b>Email:</b></td>
  22.                             <td><asp:textbox id="txtUserName" runat="server" width="160px"></asp:textbox>
  23.                             <asp:requiredfieldvalidator id="rvUserValidator" runat="server" controltovalidate="txtUserName" errormessage="You must supply a Username!"
  24.                                 display="None"></asp:requiredfieldvalidator></td>
  25.                          </tr>
  26.                          <tr>
  27.                             <td><b>Password: </b></td>
  28.                             <td><asp:textbox id="txtPassword" runat="server" width="160px" TextMode="Password" ></asp:textbox>
  29.                             <asp:requiredfieldvalidator id="rvPasswordValidator" runat="server" controltovalidate="txtPassword" errormessage="Empty Passwords not accepted"
  30.                                 display="None"></asp:requiredfieldvalidator></td>
  31.                          </tr>
  32.                          <tr>
  33.                             <td align="center" colspan="2"><asp:button id="cmdSubmit" runat="server" text="Submit" borderstyle="Solid" OnClick="cmdSubmit_Click"></asp:button></td>
  34.                         </tr>
  35.                        </table>
  36.                     </td>
  37.                 </tr>
  38.                 <tr>
  39.                     <td>
  40.                         <table id="messageDisplay">
  41.                             <tr>
  42.                        <td><asp:validationsummary id="Validationsummary1" runat="server" width="472px" displaymode="BulletList"></asp:validationsummary></td>
  43.                             </tr>
  44.                         </table>
  45.  
  46.                     </td>
  47.                 </tr>
  48.             </table>         
  49.  
  50.         </form>
  51.         <asp:label id="lblMessage2" runat="server" width="288px" font-bold="True" font-italic="True"
  52.             font-size="Medium" forecolor="#C00000"></asp:label>&nbsp;<br />
  53.         <br />
  54.  
  55. </body>
  56. </html>
  57.  
  58.  
  59. Default.aspx.cs
  60.     public partial class _Default : System.Web.UI.Page
  61.     {
  62.         protected void Page_Load(object sender, EventArgs e)
  63.         {
  64.  
  65.         }
  66.  
  67.         /* references from 1. http://www.programmingtalk.com/archive/index.php/t-2066.html
  68.          * 2. http://www.daniweb.com/forums/thread24148.html */
  69.         protected void cmdSubmit_Click(object sender, EventArgs e)
  70.         {
  71.  
  72.             if (Page.IsValid)
  73.             {
  74.                 if (DBConnection(txtUserName.Text, txtPassword.Text))
  75.                 {               
  76.                     Session["name"] = txtUserName.Text;
  77.                     FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);                                  
  78.                     Response.Redirect("home.aspx");
  79.                     if (accesslevel = 1)
  80.                     {
  81.                         Response.Redirect("home2.aspx");
  82.                     }
  83.                     else if (accesslevel = 2)
  84.                     {
  85.                         Response.Redirect("home3.aspx");
  86.                     }
  87.                 }
  88.                 else
  89.                 {
  90.                     lblMessage2.Text = "Account information is incorrect!";
  91.                 }
  92.             }
  93.  
  94.         }
  95.  
  96.         private bool DBConnection(String txtUserName, String txtPassword)
  97.         {
  98.             bool authenticated;
  99.             OdbcParameter mail;
  100.             OdbcParameter pswd;
  101.             //OdbcParameter accesslevel;
  102.             string myscalar;
  103.  
  104.             OdbcConnection myConn = new OdbcConnection(ConfigurationManager.ConnectionStrings["hrTraining"].ConnectionString);
  105.             OdbcCommand cmd = new OdbcCommand("SELECT email, password, name, id, userlevel FROM hris WHERE (email = '" + txtUserName + "' AND password = '" + txtPassword + "')", myConn);
  106.  
  107.             mail = cmd.Parameters.Add("?email", OdbcType.Char, 40);
  108.             mail.Value = txtUserName;
  109.  
  110.             pswd = cmd.Parameters.Add("?password", OdbcType.VarChar, 40);
  111.             pswd.Value = txtPassword;
  112.  
  113.             //accesslevel = cmd.Parameters.Add("?userlevel", OdbcType.Int);            
  114.  
  115.             myConn.Open();
  116.             //cmd.ExecuteNonQuery();
  117.  
  118.             OdbcDataReader reader = cmd.ExecuteReader();           
  119.  
  120.             if (reader.Read())
  121.             {                
  122.                 myscalar = cmd.ExecuteScalar();
  123.                 Session["userID"] = myscalar;
  124.                 authenticated = true;                 
  125.             }
  126.             else
  127.             {
  128.                 authenticated = false;
  129.             }
  130.  
  131.             reader.Close();
  132.             myConn.Close();
  133.             myConn.Dispose();
  134.  
  135.             return authenticated;
  136.         }
  137.     }
Dec 19 '07 #1
2 1236
bala2it4u
30 New Member
if (reader.Read())
{
myscalar = cmd.ExecuteScalar();
Session["userID"] = myscalar;
authenticated = true;
}

stort the access level in database and retreave level from database ,we can get user name from texrbox itself no need to go and get it from database
Dec 19 '07 #2
bungek84
4 New Member
if (reader.Read())
{
myscalar = cmd.ExecuteScalar();
Session["userID"] = myscalar;
authenticated = true;
}

stort the access level in database and retreave level from database ,we can get user name from texrbox itself no need to go and get it from database
hi bala2it4u..
i think myb u misunderstood what exactly i want here..let me give some brief to u..since user want to login, they should key in their email and password..n after dats, i want make their name appear on every page..dats the problem now..i dunno how to call the username itself..
Dec 21 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.