Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Login issue

Author  Topic 

simflex
Constraint Violating Yak Guru

327 Posts

Posted - 2010-02-16 : 09:42:19
Greetings experts,

I *really* need your assistance.

I have been having this issue now for 3 days and can't seem to get any help anywhere.

History: We are a classic ASP shop but recently, management wants to keep up with technology and want us to begin new developments in .net.

My first stint at doing so has hit a snag.

First we have 4 different groups who will be using the system.

Each group has their own sections to use.

So, the login is supposed to check the groupID of each user and redirect that user to his/her own group based on groupID.

I am really stumped and I would really, really appreciate your patience and assistance.

This is very new to us.

Here is the code I have been using now for 3 days.

Many thanks in advance.

Here is the web form:
<form id="form1" runat="server">
<div align=center>
<asp:Login ID="Login1" runat="server" CssClass="LoginControl"
InstructionText="<img src='images/user.gif'> Please enter your user name and password for login."
onauthenticate="Login1_Authenticate" onloginerror="Login1_LoginError">
<TitleTextStyle BackColor="#507CD1" Font-Bold="True" ForeColor="#FFFFFF" />
</asp:Login>
</div>
<asp:Label ID="MessageLabel" runat="server" ForeColor="#284E98"></asp:Label>
</form>

Then codeFile:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
ViewState["LoginErrors"] = 0;
}
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
if (validateUsers(Login1.UserName, Login1.Password))
{
e.Authenticated = true;
}
else
{
e.Authenticated = false;
}
}
protected void Login1_LoginError(object sender, EventArgs e)
{
if (ViewState["LoginErrors"] == null)
{
ViewState["LoginErrors"] = 0;
}
int ErrorCount = (int)ViewState["LoginErrors"] + 1;
ViewState["LoginErrors"] = ErrorCount;
if ((ErrorCount > 3) && (Login1.PasswordRecoveryUrl != string.Empty))
{
Response.Redirect(Login1.PasswordRecoveryUrl);
}
}
private bool validateUsers(string UserName, string Password)
{
bool boolReturnValue = false;
string strConnection = "data source = AD693;initial catalog = DWebRpts;Integrated Security=SSPI;";
SqlConnection sqlConnection = new SqlConnection(strConnection);
string SQLQuery = "SELECT UserName, GroupID, AccessLevel, UPassword FROM tblAppUser";
SqlCommand command = new SqlCommand(SQLQuery, sqlConnection);
SqlDataReader Dr;
sqlConnection.Open();
Dr = command.ExecuteReader();
Dr.Read();
{
if ((UserName == Dr["UserName"].ToString()) & (Password == Dr["UPassword"].ToString()))
{
boolReturnValue = true;
}

return boolReturnValue;
}
return boolReturnValue;
}

protected void Login1_LoggedIn(object sender, EventArgs e)
{
string Groupid= String.Empty;
string AccessLevel = String.Empty;
string strConnection = "data source = AD693;initial catalog = DWebRpts;Integrated Security=SSPI;";
SqlConnection sqlConnection = new SqlConnection(strConnection);
string SQLQuery = "SELECT GroupID, AccessLevel FROM tblAppUser where UserName=@username";
SqlCommand command = new SqlCommand(SQLQuery, sqlConnection);
command.Parameters.AddWithValue("@username", Login1.UserName);
SqlDataReader Dr;
sqlConnection.Open();
Dr = command.ExecuteReader();
Dr.Read();
{
Groupid = Dr["GroupID"].ToString();
AccessLevel = Dr["AccessLevel"].ToString();
}
if(Groupid =="FRD")
{
Response.Redirect("~/frd.aspx");
}
else if (Groupid =="PWD")
{
Response.Redirect("~/pwd.aspx");
}
}
}

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2010-02-28 : 16:13:59
so what is the error message ?
Go to Top of Page

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-02-28 : 16:20:42
if you're using integrated security, then why are you checking username/password?
Go to Top of Page
   

- Advertisement -