Click here to Skip to main content
15,924,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
I'm trying to create a login page that allows user to enter his windows user id and password in 2 text boxes to logs user in the site.
Text boxes are:
txtUserId, and txtPassword
now I want to do the following algorithm:
if txtUserId.Text = windows user id AND txtPassword.Text = windows password Then go to next page
otherwise display a message "Wrong User ID or Password."

Can anybody helps me?

Thak you.
Posted

Try:
C#
public bool CheckAuthentication()
{      
      System.Security.Principal.IPrincipal currUser;
      bool isCurrentUserAuthenticated = false;
            
      currUser = System.Web.HttpContext.Current.User;
      if (currUser.Identity.IsAuthenticated)
      {
            // Do stuff related to authenticated case
            isCurrentUserAuthenticated = true;
      }
      else
      {
             // Do stuff related to NOT authenticated case
      }      
      return isCurrentUserAuthenticated ;
}
 
Share this answer
 
v2
Comments
fadi77_net 24-Oct-10 9:55am    
dear sandeep
thak you for your answer, but I want to compare between text boxes values with UserID and Passwords of windows. Your function can ONLY get the user id, but it cannot get windows password, and it is not reading from the windows active directory.
Sandeep Mewara 24-Oct-10 10:08am    
Well,
1. it is reading from windows active directory :) (currUser.Identity does that)
2. for windows authentication, you don't need to put your textboxes for username.password. It is taken care of by browser itself.

Just put this code and all is done.
fadi77_net 25-Oct-10 1:46am    
I tried the code in login control, but it did't accept my password and displayed this message :"Your login attempt was not successful. Please try again."
I cannot access the next page.
do you have any idea?
Have a look at this article. Read it. It tell all and how windows authentication can be enabled and works:
Windows Authentication implemented in ASP.NET[^]

Details on Windows authentication here:
Link 1[^]
Link 2[^]
 
Share this answer
 
Comments
fadi77_net 26-Oct-10 5:46am    
I read it
that is no working.
Sandeep Mewara 26-Oct-10 6:04am    
Well, you are surely doing something wrong. I already have this in place and the articles are just fine.

It would be difficult to tell online what are you missing.
Member 9550790 21-Jun-18 2:53am    
I'm sorry to say this Mr. Mewara but I think it's you who is doing something wrong - not reading the question properly. This guy is clearly asking for the authentication against the Active Directory. It is way older post so I don't think there's any point asking for solution but if anybody has one, please post the answer.

Thanks!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900