How to get the user machine's login name? - asp.net

I'm developing a system in ASP.NET which needs user authentication. The authentication system should look up to the login name in the user machine instead of typing the username in the textbox. Then, if it's registred in the database, it should log in automatically.
How do I get, by code, the user machine's login name?

You can use:
User.Identity.Name
This is found in the HttpContext.User Property.

Try a couple of these options:
Request.ServerVariables("LOGON_USER")
Request.ServerVariables("REMOTE_USER")
Request.ServerVariables("AUTH_USER")

Unless this is an intranet application and you're using Windows Authentication, there is no way to get that information.
If you enable Windows Authentication, the user will be prompted to enter their domain credentials, after which you'll be able access their username like this:
string userName = User.Identity.Name;

Related

Form authentication with tomcat (AES)

1.I am having a web app in which a user can register by providing new user id and password and i am encrypting the password using AES and storing it in my postgres database
For user welcome page I want to use form based authentication using tomcat
But for that i first need the user to login in my login page then i decrpyt the password in my database and check it with the user entering password
But from my understanding so far about tomcat authentication i need to use password="j_password" for password validation
but my database contains only encrypted password so hope you get my question
please help!! Thanks in advance.....

IIS ASP.NET Impersonation: specific user specified but User.Identity is blank

The application works well (meaning, User.Identity.Name is properly identified) when:
Anonymous Authentication is Disabled
ASP.NET Impersonation is Enabled, and set to use Authenticated User
Windows Authentication is Enabled
Now, the user will be accessing it outside the domain, and should not be required to enter his login/password but still be authenticated.
So, I simply did the following:
Anonymous Authentication Enabled
Set ASP.NET Impersonation to this user domain name and password
Windows Authentication is Disabled (although it would not make a difference in this case)
The application is loading, but User.Identity.Name is black and I expected it to have the user specified in the ASP.NET Impersonation. I need this User.Identity.Name to be a valid user because it's used later inside the app.
Any help?
By design "anonymous" means that you don't know who is connected.User.Identity.The name might be empty if Anonymous Authentication is enabled in IIS.
you can use the below code to check if the identity is available.
if (User.Identity.IsAuthenticated)
Label1.Text = User.Identity.Name;
else
Label1.Text = "No user identity available.";
You could also use "profile migration".

change sql server login username

I have asp.net application that have a connection string using windows authentication.my system work in network domain.
When I try to open application connection string use this domain\Machin Name for login.
But I want change it to this domain\MyUserName,
how I can do it?
You need to pass IP address of server in the Server, database name, and credentials mainly username and password, here is sample to do like this:
data source=ServerIp;Initial Catalog=DatabaseName;user Id=Username;
Password=Password;
if it doesn't have a default server connection then need to change server as (serverip)(sql instance). like 192.16.3.1\SQLEXPRESS
there will have default sa username and password, if u don't know it create new user in sql mananagement studio => security => Logins
You have to create a new User for this problem as below:
Create new user with Administrator privilege with same username and password.
On SQL Server database create new user by expanding DatabaseNode->Security->Login->Create New User and add this new user with Windows Authentication radio button selected. This user can be only added by selected Windows Authentication it is Operating system’s User Login.
Linked: https://blog.sqlauthority.com/2008/11/02/sql-server-fix-error-login-failed-for-user-username-the-user-is-not-associated-with-a-trusted-sql-server-connection/

Using Windows Live Id Authentication with my own login form

I want to use the Windows Live Id Authenticaiton in my Asp.Net/MVC web application, but I do not want to use the Login screen provided by Microsoft.
I want to have my custom page for login, take username and password from User and then send these credentials to the Windows Live ID, to Authenticate, and I get back the response if the user is authenticated or not.
Is this possible?
I want to have my custom page for login, take username and password from User and then send these credentials to the Windows Live ID, to Authenticate, and I get back the response if the user is authenticated or not.
You missed the point of single sign-on authentication. Using that, the user does not provide their credentials to your site, but to the SSO provider. That provider gives you a token which lets you act on behalf of the authenticated user.
The user's credentials are never received by your site.
So no, you cannot, nor should you want to, do this.

How do you get the logged in Windows domain account from an ASP.NET application?

We have an ASP.NET application that manages it's own User, Roles and Permission database and we have recently added a field to the User table to hold the Windows domain account.
I would like to make it so that the user doesn't have to physically log in to our application, but rather would be automatically logged in based on the currently logged in Windows domain account DOMAIN\username. We want to authenticate the Windows domain account against our own User table.
This is a piece of cake to do in Windows Forms, is it possible to do this in Web Forms?
I don't want the user to be prompted with a Windows challenge screen, I want our system to handle the log in.
Clarification: We are using our own custom Principal object.
Clarification: Not sure if it makes a difference or not, but we are using IIS7.
Integration of this sort is at the server level, it's IIS that decides that the user is not logged in; and it's IIS that sends back the authentication prompt to the user, to which the browser reacts.
As you want to use the domain login there is only one way to do this; integrated windows authentication. This will only work if the IIS server is also part of the domain and the users are accessing the machine directly, not through a proxy, and from machines which are also part of the domain (with the users suitably logged in).
However your custom principal object may create fun and games; authentication of this type will be a WindowsPrincipal and a WindowsIdentity; which you can access via the User object (see How To: Use Windows Authentication in ASP.NET 2.0)
I assume you want a custom principal because of your custom roles? I doubt you can get the two to play nicely; you could create a custom role provider which looks at your data store or look at you could look at ADAM, an extension to AD which provides roles on a per program basis and comes with nice management tools.
I did pretty much exactly what you want to do a few years ago. Im trying to find some code for it, though it was at a previous job so that code is at home.
I do remember though i used this article as my starting point. You set up the LDAP provider so you can actually run a check of the user vs the LDAP. One thing to make sure of if you try the LDAP approach. In the setting file where you set up the LDAP make sure LDAP is all caps, if it is not it will not resolve.
using System.Security.Principal;
...
WindowsPrincipal wp = (WindowsPrincipal)HttpContext.Current.User;
to get the current domain user. Of course you have to make sure that the IIS is set up to handle Windows Authentication.
This might be helpful:
WindowsIdentity myIdentity = WindowsIdentity.GetCurrent();
WindowsPrincipal myPrincipal = new WindowsPrincipal(myIdentity);
string name = myPrincipal.Identity.Name;
string authType = myPrincipal.Identity.AuthenticationType;
string isAuth = myPrincipal.Identity.IsAuthenticated.ToString();
string identName = myIdentity.Name;
string identType = myIdentity.AuthenticationType;
string identIsAuth = myIdentity.IsAuthenticated.ToString();
string iSAnon = myIdentity.IsAnonymous.ToString();
string isG = myIdentity.IsGuest.ToString();
string isSys = myIdentity.IsSystem.ToString();
string token = myIdentity.Token.ToString();
Disclaimer: I got this from a technet article, but I can't find the link.
You can use System.Threading.Thread.CurrentPrincipal.
Request.ServerVariables["REMOTE_USER"]
This is unverified for your setup, but I recall using this awhile back.
Try Request.ServerVariables("LOGON_USER").
If the directory security options are set so that this directory does not allow anonymous users, when the surfer hits this page they will be prompted with the standard modal dialog asking for username and password. Request.ServerVariables("LOGON_USER") will return that user.
However, this will probably not work for you because you are using your own custom security objects. If you can figure out how to get around that logon box, or pass in NT credentials to the site before it askes for them, then you would be all set.
Have you thought about impersonation? You could store the user's NT logon credentials in your custom security object, and then just impseronate the user via code when appropriate.
http://msdn.microsoft.com/en-us/library/aa292118(VS.71).aspx

Resources