Re: Validating a user using SSPI
From: Pieter Philippaerts (Pieter_at_nospam.mentalis.org)
Date: 12/05/03
- Next message: Mallikarjun Tuppad: "Re: smart client - different error."
- Previous message: Brad: "Re: StrongNameIdentityPermission at Assembly level?"
- In reply to: Edwin: "Validating a user using SSPI"
- Next in thread: Joe Kaplan \(MVP - ADSI\): "Re: Validating a user using SSPI"
- Reply: Joe Kaplan \(MVP - ADSI\): "Re: Validating a user using SSPI"
- Reply: Pieter Philippaerts: "Re: Validating a user using SSPI"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Fri, 5 Dec 2003 17:17:54 +0100
"Edwin" <Edwin.Loubser@comau.co.za> wrote in message
> My problem is trying to authenticate using windows
> integrated security, based on the user name and password
> supplied by the user.
You can use the WindowsIdentity class for this. The constructor expects a
token generated by LogonUser, so you'll have to do some P/Invoke too.
Here's some code that you can use: [warning: untested air code]
using System.Runtime.InteropServices;
using System.Security.Principal;
[DllImport("advapi32.dll")]
static extern int LogonUser(string Username, string Domain, string Password,
int LogonType, int LogonProvider, ref IntPtr Token);
private IPrincipal Authenticate(string user, string pass) {
m_ClientSocket.Send(new byte[]{5, 0});
IntPtr token = IntPtr.Zero;
int ret = LogonUser(user, ".", pass, 2, 0, ref token);
if(ret == 0)
throw new SecurityException();
WindowsIdentity wi = new WindowsIdentity(token);
return new WindowsPrincipal(wi);
}
Once you have an IPrincipal instance, you can use IsInRole method to check
whether a user belongs to a certain group.
Regards,
Pieter Philippaerts
Managed SSL/TLS: http://www.mentalis.org/go.php?sl
- Next message: Mallikarjun Tuppad: "Re: smart client - different error."
- Previous message: Brad: "Re: StrongNameIdentityPermission at Assembly level?"
- In reply to: Edwin: "Validating a user using SSPI"
- Next in thread: Joe Kaplan \(MVP - ADSI\): "Re: Validating a user using SSPI"
- Reply: Joe Kaplan \(MVP - ADSI\): "Re: Validating a user using SSPI"
- Reply: Pieter Philippaerts: "Re: Validating a user using SSPI"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|