473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Current Login to another machine

Dear All,

I would like to perform a simple task by program (VB.Net or VC#.Net).

When a user logins the windows and try to run my program, how can I use his login information (username and password) to authenicate against another PC, e.g. using DirectoryEntry object?

I have these lines of code, but it needs the user to enter username and password in Textboxes txtUsername and txtPassword respectively. I would like to use the current login session information to do the job instead..
System.DirectoryServices.DirectoryEntry usr = new DirectoryEntry(entryPC.Path, txtUsername.Text, txtPassword.Text);
string strUserID;
try
{
strUserID = usr.NativeGuid;
MessageBox.Show("Login correct!");
}
catch
{
MessageBox.Show("Login Incorrect!");
}

Thanks for your help.
--------------------------------
From: Stephen Yip

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>EHsuCqGmSUa45Rjc8gxZLg==</Id>
Jul 21 '05 #1
2 1617
You can't get the password from an authenticated logon session (thank God).
I'm not clear on why you want to authenticate an authenticated user on
another PC?

Willy.

"Stephen Yip via .NET 247" <an*******@dotnet247.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
Dear All,

I would like to perform a simple task by program (VB.Net or VC#.Net).

When a user logins the windows and try to run my program, how can I use
his login information (username and password) to authenicate against
another PC, e.g. using DirectoryEntry object?

I have these lines of code, but it needs the user to enter username and
password in Textboxes txtUsername and txtPassword respectively. I would
like to use the current login session information to do the job instead..
System.DirectoryServices.DirectoryEntry usr = new
DirectoryEntry(entryPC.Path, txtUsername.Text, txtPassword.Text);
string strUserID;
try
{
strUserID = usr.NativeGuid;
MessageBox.Show("Login correct!");
}
catch
{
MessageBox.Show("Login Incorrect!");
}

Thanks for your help.
--------------------------------
From: Stephen Yip

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>EHsuCqGmSUa45Rjc8gxZLg==</Id>

Jul 21 '05 #2


Hi,

You dont need to authenicate again to access "X" pc. You
can use current session and can access "X"(if you have
permissions).

IntPtr token = new IntPtr(0);
bool isValidUser = LogonUser(txtLoginName.Text,
txtDomain.Text, txtPassword.Text, (int)
LOGON32_LOGON_NETWORK, (int)LOGON32_PROVIDER_DEFAULT, ref
token);

if(isValidUser == false)
{

Msg.Text = "Wrong user
name or password<br>";
}
else
{
IntPtr token2 = new IntPtr
(token.ToInt32());
WindowsIdentity l_Wid =
new WindowsIdentity(token2);
WindowsPrincipal wp = new
WindowsPrincipal(l_Wid);

System.Threading.Thread.CurrentPrincipal = wp;

HttpContext.Current.User =
wp;
//////////////////////////
// Declare the logon types as constants
const long LOGON32_LOGON_INTERACTIVE = 2;
const long LOGON32_LOGON_NETWORK = 3;

// Declare the logon providers as constants
const long LOGON32_PROVIDER_DEFAULT = 0;
const long LOGON32_PROVIDER_WINNT50 = 3;
const long LOGON32_PROVIDER_WINNT40 = 2;
protected
System.Web.UI.WebControls.TextBox TextBox1;
const long LOGON32_PROVIDER_WINNT35 = 1;

[DllImport("advapi32.dll",EntryPoint
= "LogonUser")]
private static extern bool LogonUser(
string lpszUsername,
string lpszDomain,
string lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken);
-----Original Message-----
Dear All,

I would like to perform a simple task by program (VB.Net or VC#.Net).
When a user logins the windows and try to run my program, how can I use his login information (username and
password) to authenicate against another PC, e.g. using
DirectoryEntry object?
I have these lines of code, but it needs the user to enter username and password in Textboxes txtUsername and
txtPassword respectively. I would like to use the current
login session information to do the job instead..System.DirectoryServices.DirectoryEntry usr = new DirectoryEntry(entryPC.Path, txtUsername.Text,
txtPassword.Text);string strUserID;
try
{
strUserID = usr.NativeGuid;
MessageBox.Show("Login correct!");
}
catch
{
MessageBox.Show("Login Incorrect!");
}

Thanks for your help.
--------------------------------
From: Stephen Yip

-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)

<Id>EHsuCqGmSUa45Rjc8gxZLg==</Id>
.

Jul 21 '05 #3

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

Similar topics

11
by: Ghazan Haider | last post by:
I am posting this for the lack of a better newsgroup, and for the knowledge of people here, and because its only partially OT. We have a bunch of users with their computers at work. There are...
11
by: David W. Simmonds | last post by:
I have a form that will prompt for a user name/password. In VS.NET, I have the protected form in a folder named Admin. I have a Web.config file in that folder as well. It contains the following...
4
by: Kristof Despiere | last post by:
Suppose you have one domain, filled with a couple of users. What needs to be done now is I need to start a windows application from a webform by pressing a button on the webform (for example). ...
0
by: Mach Runner | last post by:
I am implementing a secure website using the ASP.NET FormsAuthentication model. I have taken the simplest code examples from MSDN (login.aspx,default.aspx, web.config) but cannot get proper...
2
by: Stephen Yip via .NET 247 | last post by:
Dear All, I would like to perform a simple task by program (VB.Net or VC#.Net). When a user logins the windows and try to run my program, how can I use his login information (username and...
3
by: SAL | last post by:
Hello, I'm a total asp.net newbie. I'm developing a web app and on my machine I login to a sql server just fine using NT Authentication via the connection string as: Integrated Security=True ...
2
by: dougloj | last post by:
Hi. I have an ASP.NET application written in C#. To log in, a user must provide their email address and password. I already give the user a "Remember my Email Address" check box. If they check...
6
by: Kat | last post by:
Every time I attempt to run a localhost website, it asks me for a login, as if I am not a user on the local machine. I am a user on the local machine, I am an admin on the local machine. I am not...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I want to limit the user only login the system one time at the same time. I don't want him login the system two with the same user at the same time. How to do this? If i have a table to record...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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,...

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.