Showing posts with label username. Show all posts
Showing posts with label username. Show all posts

Monday, March 26, 2012

Pass Username and Pwd to database query in WebMartix?

I have an application that uses a login screen to pass UserName and Password to a details page. Then I use a SELECT query to generate a datagrid using UserName and Pwd as WHERE clause.

I have inserted a couple of label.texts to verify the variable make the second page.

How do I get the query to limit the return to only the records matching the UserName & Pwd combination?

Thanks,
ScottYou don't really want to pass the password around your site. And hopefully you're not allowing multiple duplicate usernames as long as the password is different.

If you're using asp.net authentication then it's somewhat safe to assume that the username is valid once they're logged in.

I.E. on your login page you set an authorization cookie.

On your details page you access their username via this cookie and use that as a parameter to your stored procedure/SQL Query.

Pass UserID instead of Username to other pages after logged on, ASP.NET 2.0

Hi,
I have my own user table with definition like
UserID int not null primary key,
Username varchar(50) not null,
Password varchar(50) not null,
Firstname varchar(50) not null,
Lastname varchar(50) not null,
Email varchar(50) not null,
....
I create my own Membership provider to inherit SqlMembershipProvider
public class MyMembershipProvider :
System.Web.Security.SqlMembershipProvider {
public MyMembershipProvider() {
}
public override bool ValidateUser(string username, string password) {
// query my DB to verify user
MyUser mu = new MyUser();
return mu.VerifyUser(username, password);
}
}
In Asp.Net 1.1, we can use
FormsAuthentication.RedirectFromLoginPage(UserID.ToString(), false); to save
UserID (which is whatever I return from my own function, including UserID
from User table). Later on, we just call User.Identity.Name to retrieve the
UserID and it could be used as I like.
But in ASP.NET 2.0, I just need to add
<membership defaultProvider="MyMembershipProvider">
<providers>
<add name="MyMembershipProvider"
type="MyMembershipProvider"/>
</providers>
</membership>
to my web.config file, it will handle authentication autimatically. In this
case how can I pass UserID instead of username to other pages?
Thanks
HardyHardy,
Why pass it around? Why not set a session variable with the information
you need?
- Nicholas Paldino [.NET/C# MVP]
- mvp@.spam.guard.caspershouse.com
"Hardy Wang" <hardywang@.hotmail.com> wrote in message
news:umAPpLP%23FHA.1988@.TK2MSFTNGP12.phx.gbl...
> Hi,
> I have my own user table with definition like
> UserID int not null primary key,
> Username varchar(50) not null,
> Password varchar(50) not null,
> Firstname varchar(50) not null,
> Lastname varchar(50) not null,
> Email varchar(50) not null,
> ....
> I create my own Membership provider to inherit SqlMembershipProvider
> public class MyMembershipProvider :
> System.Web.Security.SqlMembershipProvider {
> public MyMembershipProvider() {
> }
> public override bool ValidateUser(string username, string password) {
> // query my DB to verify user
> MyUser mu = new MyUser();
> return mu.VerifyUser(username, password);
> }
> }
> In Asp.Net 1.1, we can use
> FormsAuthentication.RedirectFromLoginPage(UserID.ToString(), false); to
> save UserID (which is whatever I return from my own function, including
> UserID from User table). Later on, we just call User.Identity.Name to
> retrieve the UserID and it could be used as I like.
> But in ASP.NET 2.0, I just need to add
> <membership defaultProvider="MyMembershipProvider">
> <providers>
> <add name="MyMembershipProvider"
> type="MyMembershipProvider"/>
> </providers>
> </membership>
> to my web.config file, it will handle authentication autimatically. In
> this case how can I pass UserID instead of username to other pages?
>
> Thanks
> Hardy
>

Wednesday, March 21, 2012

Passing a Querry string in a Response.Redirect?

I want to be able to redirect on a Button click event with a querry string attached with the username, is this possible?
would it look something like?
'Response.Redirect("link.aspx?UserId="Label.Text"") or
'Response.Redirect("link.aspx?userid=("Label.Text"))

This should do it:
Response.Redirect( "link.aspx?UserId=" & Server.UrlEncode(myLabel.Text) )