473,624 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to implement a automatic login function

hi guys.
In my project, now I am using a asp.net login control and a customized
membership provider to do the form authentication. Now I want some function
that user can skip the login form and be authenticated and login the system
automatically base on the username and password already in the session. Is
that possible to do ? and how to do it?

Cheers
Victor
Apr 1 '07 #1
10 8147
You should be able to use the authentication API from the
FormsAuthentica tion class to add/revoke a cookie for sign in status easily.
Have a look at this for example:
http://msdn2.microsoft.com/en-us/lib...uthcookie.aspx

--
~~~~~~~~~~~
Ben Rush
http://www.ben-rush.net/blog
"Victor" <vi****@noemail .noemailwrote in message
news:eS******** ******@TK2MSFTN GP06.phx.gbl...
hi guys.
In my project, now I am using a asp.net login control and a customized
membership provider to do the form authentication. Now I want some
function that user can skip the login form and be authenticated and login
the system automatically base on the username and password already in the
session. Is that possible to do ? and how to do it?

Cheers
Victor

Apr 2 '07 #2
Hi Victor,

From your description, you want to add a code function that can help
automatically make a user loggedIn without interactive operation through
the login page, correct?

As Ben has suggested, ASP.NET forms authentication provide API for us to
programmaticall y do the authentication, and make a user turn from
unauthenticated to authenticated status. For example, the following two
methods can help make the current user loggedIn(by passing a username and
boolean parameter)

#FormsAuthentic ation.RedirectF romLoginPage Method
http://msdn2.microsoft.com/en-us/lib...ormsauthentica
tion.redirectfr omloginpage.asp x

#FormsAuthentic ation.SetAuthCo okie Method
http://msdn2.microsoft.com/en-us/lib...ormsauthentica
tion.setauthcoo kie.aspx

BTW, I'm still wondering your exactly code logic and scenario in the
application, as you said that the username/password is in the session,
then, how will you store username/password in session? password should
never be persisted in memory after login/authentication.

Anyway, if you have anything unclear or anything we missed, please feel
free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 2 '07 #3
I am not sure I understand you.

Do you mean:

1. User signed in once and has come back to the site? If so, set the
persistence flag to true and the cookie will live on across all sessions.
2. User has signed in and is now surfing other pages? If so, you need to do
nothing, as the user will be signed in.
3. User has signed into another site in your domain and you wish to allow
him to hit all sites? If so, set the machines keys to the same value on all
of your sites and call the cookie, explicitly, by the same name - all in
config file. NOTE: You will not be able to switch stored session values from
site to site.
4. You want certain users to be able to fake the login and be authenticated
with another account? This can be done with the API, but how are you going
to identify those users? Think this through carefully, as it is quite easy
for a hacker to figure out he can use your site with querystrings, if that
is your method of bypassing security. If you do not like the API, you can
create MembershipUser objects and attach to an ongoing session. That will
log them in, this time.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA
http://gregorybeamer.spaces.live.com

*************** *************** ***************
Think outside the box!
*************** *************** ***************
"Victor" <vi****@noemail .noemailwrote in message
news:eS******** ******@TK2MSFTN GP06.phx.gbl...
hi guys.
In my project, now I am using a asp.net login control and a customized
membership provider to do the form authentication. Now I want some
function that user can skip the login form and be authenticated and login
the system automatically base on the username and password already in the
session. Is that possible to do ? and how to do it?

Cheers
Victor
Apr 2 '07 #4
Hi Victor,

Have you got any progress or idea on this issue or does the suggesetion in
our previous message help some? If you have any further question on this,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 5 '07 #5
On Apr 5, 3:44 am, stch...@online. microsoft.com (Steven Cheng[MSFT])
wrote:
Hi Victor,

Have you got any progress or idea on this issue or does the suggesetion in
our previous message help some? If you have any further question on this,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
I'm not sure if my issue is the same as Victor's but i need to send
the username and password via a post to the site's initial page so
that the user can be authenticated as if he had used a login control
but skip the login process altogether.

Ideally all this can be done so that the username and password is not
sent in clear text. However we are willing to use SSL if necessary.

How can a post request be fed to whatever class the login control
feeds programmatially to obtain the same authenticated result?

Thanks,

Apr 5 '07 #6
Hi Rob,

Thanks for your input.

I think what you want to do is a bit different. What you want to do is like
a web client which programmaticall y send http post request to send login
credentials and pass the login page at server-side, just like many web
crawler does, correct?

For programmaticall y post http form data (through webrequest component in
..net), here are some useful web links:

#ASP.NET: Post Data Programmaticall y with "Webscrapin g"
http://www.developer.com/net/asp/article.php/3645506

#Programmatical ly Posting Data to ASP .NET Web Applications
http://dndj.sys-con.com/read/45127.htm

#Https form post using Httpwebrequest brings back the same page.
http://www.thescripts.com/forum/thread591965.html

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.





Apr 6 '07 #7
On Apr 5, 9:27 pm, stch...@online. microsoft.com (Steven Cheng[MSFT])
wrote:
Hi Rob,

Thanks for your input.

I think what you want to do is a bit different. What you want to do is like
a web client which programmaticall y send http post request to send login
credentials and pass the login page at server-side, just like many web
crawler does, correct?

For programmaticall y post http form data (through webrequest component in
.net), here are some useful web links:

#ASP.NET: Post Data Programmaticall y with "Webscraping"ht tp://www.developer.c om/net/asp/article.php/3645506

#Programmatical ly Posting Data to ASP .NET Web Applicationshtt p://dndj.sys-con.com/read/45127.htm

#Https form post using Httpwebrequest brings back the same page.http://www.thescripts.com/forum/thread591965.html

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.
Thanks for the reply Steven,

Unfortunately, this is not what I am after.

I am simply trying to simulate a normal login. At the moment the site
uses the login control connected to the Membership class. Under a
normal login the CurrentUser is associated with the current session
and can be picked up on any page by Membership.GetU ser(). As per your
suggestion earlier in this thread I've been able to pass in the
username and password via a post and authenticate using the
following.

If Membership.Vali dateUser(UserNa me, Password) Then
FormsAuthentica tion.RedirectFr omLoginPage(Use rName, True)

At least I think it authenticates because no error is returned but I
can't really know for sure because I can pickup up the current user
name in the normal way as follows:

Dim CurrentUser As MembershipUser = Membership.GetU ser()
Message.Text = "Login Successfull. User = " & CurrentUser.Use rName

In this case Membership.GetU ser() returns a null.

Regards,

RobGMiller

Apr 6 '07 #8
Hi Victor,

Have you got any further idea on this issue? If there is anything else we
can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Apr 10 '07 #9
I've to programmaticall y login to a third party web app (Tomcat/apache) and
take the user to a landing page. I am able to programatically login
succesfullly but I am not able to redirect the browser to the landing page.
If I look at the logs on Tomcat side, I see the cookies are getting lost
somewhere even though I pass the cookies between successive requests. I would
appreciate any comments or suggestion rgeading how to take the user
successfully to the landing page.

string url = "http://10.112.60.86:80 80/PCC/servlet/tpservlet";
HttpWebRequest req = (HttpWebRequest )WebRequest.Cre ate(url);
CookieContainer CookieC = new CookieContainer ();

string data =
String.Format(" USERID={0}&tran sactiontype={2} &FIID={3}&AUTHE NTICATIONURL={4 }&TARGET={5}" ,
"DDBDB3099C5C04 D36B91C0EA786C0 996", "729E13B7AFB577 96A30",
"UserInqAuthAct ionBean", "1111",
"http://atl50test2/CLKPCB/111111118/Site/TransfersPaymen ts/opserror.asp",
"BillPay.viewPa yees");
byte[] buffer = Encoding.UTF8.G etBytes(data);
req.AllowAutoRe direct = false;
req.KeepAlive = true;
req.Method = "POST";
req.ContentType = "applicatio n/x-www-form-urlencoded";
req.ContentLeng th = buffer.Length;
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1;
..NET CLR 1.1.4322; .NET CLR 2.0.50727)";
req.CookieConta iner = CookieC;

Stream reqst = req.GetRequestS tream(); // add form data to request
stream
reqst.Write(buf fer, 0, buffer.Length);
reqst.Flush();
reqst.Close();

HttpWebResponse res = (HttpWebRespons e)req.GetRespon se();
string landingpage= res.Headers["Location"];
CookieC.Add(res .Cookies);
foreach (Cookie cook in CookieC.GetCook ies(req.Request Uri))
{
HttpCookie cookie = new HttpCookie(cook .Name);
cookie.Name = cook.Name;
cookie.Value = cook.Value;
cookie.Domain = cook.Domain;
cookie.Expires = cook.Expires;
cookie.Path = cook.Path;
cookie.Secure = cook.Secure;

String str = String.Format(" Name {0}: Value {1}: Domain
{2}<BR>", cookie.Name, cookie.Value, cookie.Domain);
HttpContext.Cur rent.Response.A ppendCookie(coo kie);

}
//This statement fails
HttpContext.Cur rent.Response.R edirect(landing page);

I have to do the similar thing like automatically login to a third pary web

"Steven Cheng[MSFT]" wrote:
Hi Victor,

Have you got any further idea on this issue? If there is anything else we
can help, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 8 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2728
by: R. Rajesh Jeba Anbiah | last post by:
Q: How to implement a login system? A: Use sessions. When the user logins, store the session id in the database and then compare the current session id with the one stored in the database on every page. May also check IP; but it may break if the user is behind proxy. Refer: http://www.php.net/session http://www.mt-dev.com/2002/07/creating-a-secure-php-login-script/ http://www.mt-dev.com/2002/09/php-login-script/
2
8463
by: Paul M. | last post by:
Hi, we have 2 www systems one which we wrote ourselves the other is a parent company one over which we have no control. The 2nd system involves the user having to enter a username & password in a login screen. Is there any way of calling the 2nd systems login page and having the username & password be inserted automatically? This auto passing in of information might also be applied to optins selection so instead of manually clicking on...
2
4656
by: James X. Li | last post by:
Is there a way to implement multiple login forms for ASP.NET applications? With our application we want to implement simple login form for normal resources (downloadable files), but more rigorous login forms for tasks like administration and configuration. The current ASP.NET seems only to allow to a single login form via the authentication element in web.config in the root directory. One work-around for our problem is implementing a...
3
2313
by: alex | last post by:
I want to implement an async-function,just like Oracle OCI function: for example: I call oci "execute(strSQL)" function, and I can call "cancle" function to cancle the process if the SQL execute too long. How to implement the execute and cancle functions? thx!
3
6184
by: mikey.mor | last post by:
Hello everyone, i am trying to do the folowing : 1. login to HTTPS website ( gmail for example ). 2. go to a certain page in that website. 3. read the page's content. how is it best to achievve this ?
6
1723
by: bb nicole | last post by:
Below is my login function, but it cant display the username correctly, i don't know what is the problem. Thanx.. LOGIN FUNCTION <?php extract ($_POST); mysql_connect("localhost","root","")
9
2400
by: bb nicole | last post by:
I want 2 use session in my login, but i never use session before. How to change my code as below if i want to use session... Can somebody give me some opinion, please.. Thanks a lot.. Below is my php code.. LOGIN FUNCTION <?php extract ($_POST); mysql_connect("localhost","root","") or die("Cannot connect to the server"); mysql_select_db("ums e-job portal")
3
1814
by: madhumathikv | last post by:
Hi all, How to implement automatic completion i.e, suppose Assume that there are commands like show show version show ip show arp As soon as you press "s" and tab it should display "show ".
0
1318
by: kang jia | last post by:
hi i have small problems occurred in my login function, which i use Django to build, in my template which is login.html, the code is like the following: <html> <head> <title>Login</title>
0
8233
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6108
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4078
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.