Đăng nhập | Đăng ký
Đăng nhập , với với

Diễn đàn    Window Form programming    Đăng nhập dùng tài khoản của windows  

Thành viênNội dung
aspnet

Lập trình không biên giới
446  bài
24-03-2009 02:06:17
public class WindowAuthenticate
{
[DllImport("advapi32.dll", SetLastError = true)]
static extern bool LogonUser(
string principal,
string authority,
string password,
LogonSessionType logonType,
LogonProvider logonProvider,
out IntPtr token);
[DllImport("kernel32.dll", SetLastError = true)]
static extern bool CloseHandle(IntPtr handle);
enum LogonSessionType : uint
{
Interactive = 2,
Network,
Batch,
Service,
NetworkCleartext = 8,
NewCredentials
}
enum LogonProvider : uint
{
Default = 0, // default for platform (use this!)
WinNT35, // sends smoke signals to authority
WinNT40, // uses NTLM
WinNT50 // negotiates Kerb or NTLM
}

public static bool UserLogin(string username, string domain, string password, System.Web.HttpResponse response)
{
IntPtr token = IntPtr.Zero;
WindowsImpersonationContext impersonatedUser = null;

try
{
// Create a token for DomainName\Bob
// Note: Credentials should be encrypted in configuration file
bool result = LogonUser(username, domain,
password,
LogonSessionType.Interactive,
LogonProvider.Default,
out token);
if (result)
{
WindowsIdentity id = new WindowsIdentity(token);

// Begin impersonation
impersonatedUser = id.Impersonate();
string full_username = WindowsIdentity.GetCurrent().Name;
System.Web.Security.FormsAuthentication.SetAuthCookie(full_username, false);

return true;
}
else
{
response.Write("</p>LogonUser failed: " +
Marshal.GetLastWin32Error().ToString());
}
}
catch
{
// Prevent any exceptions that occur while the thread is
// impersonating from propagating
}
finally
{
// Stop impersonation and revert to the process identity
if (impersonatedUser != null) impersonatedUser.Undo();
// Free the token
if (token != IntPtr.Zero) CloseHandle(token);
}

return false;
}
}
 

Chủ đề gần đây :

Cùng loại :

 
Tên file Người đăng Ngày Lượt
News Ticker Demo.rar
jQuery Carousellite cho cuộn các khối tin nhẹ nhàng mượt mà, sử dụng cho module Tin tức (CMS) hoặc giới thiệu sản phẩm
aspnet 5/7/2011 8:59:52 AM 660
cms_source_dll_sql_2010.rar
source C# + SQL Script + Dll module CMS trên DNN 5x, (bản chạy ổn định không lỗi)
aspnet 9/5/2010 6:05:54 PM 2148
killforever.rar
Script diệt virus forever.exe (lây nhiễm qua USB) mà không cần cài lại window
aspnet 7/28/2010 6:51:30 AM 304
CSharp Coding Standards.pdf
C# Coding standard, for all user, quy tắc viết mã lập trình c# dotnet.
aspnet 6/1/2010 8:27:39 AM 1371
weather_forex_gold.rar
module DNN : "vàng + thời tiết + tỷ giá ngoại tệ" của seekill
coder 3/11/2010 3:50:09 AM 1239
Training DotNetNuke.zip
Tài liệu hướng dẫn cài đặt DNN, tạo module DNN đơn giản, nâng cao
quanlv 9/30/2009 9:11:36 AM 3258
Viet va them 1 module don gian vao website.doc
Hướng dẫn viết module đơn giản trên DNN (word) có hình, gửi bởi vinahana
aspnet 9/18/2009 6:15:24 PM 1564
Moduel NEWs Demo.zip
Một số module bao gồm: News, WorkScheduler, QA, Comment, Menu, ...
quanlv 8/22/2009 10:44:15 AM 2923
MenuDNN5.rar
Menu DNN 51 Page.aspx
aspnet 7/21/2009 12:22:38 PM 2039
diendan.zip
Cài đặt diễn đàn (VSP) chỉ với 4 bước.
aspnet 6/15/2009 2:18:13 AM 1516
roll_updown.zip
Roll up, roll down news list using javascript, simple, easy to use.
radiogaga 6/1/2009 11:29:51 AM 456
rotator-1.0.0.rar
Auto Scroll News - tự động cuộn tin tức bằng JS
dotnetvn 5/30/2009 3:21:22 PM 682
captcha2.rar
CAPTCHA sinh ngẫu nhiên : size, font, position, color ... vẽ line gây nhiễu chống reCAPTCHA bot.
tieuphu 5/30/2009 2:34:42 PM 669
MenuDNN.zip
Menu Dọc cho DNN (Tác giả Võ Thế Quang)
biennv 5/27/2009 8:07:47 AM 1551
Gioi_thieu_san_pham_unisched4.zip
Giới thiệu phần mềm xếp thời khóa biểu đại học (University Scheduling 4.0) : áp dụng cho mô hình xếp thời khóa biểu niên chế, tại các trường đại học và cao đẳng tại việt nam
khanhjin 5/12/2009 5:00:02 PM 3418
HitCounterInDatabaseASPNET.zip
HitCounter
nguyentx 4/20/2009 4:38:04 PM 600
s3Slide.rar
Slide show chuyên nghiệp, giống tintuconline.com.vn
coder 4/9/2009 9:34:41 AM 2470
XMLPROG.zip
XML Programing C# dotnet
aspnet 4/4/2009 10:02:43 AM 652
menu_vnexpress.rar
Tạo menu giống vnexpress = xsl transform, C# dotnet, javascript(Toàn bộ mã nguồn).
coder 3/30/2009 10:14:50 PM 2627
DesktopModules.rar
CMS dotnetnuke + Image Library + Core CMS (DNN Data Provider) version 1.1
aspnet 3/30/2009 5:23:14 PM 2212
CODERVN.NET
Công ty cổ phần công nghệ và dịch vụ AWAS
Công ty cổ phần công nghệ và dịch vụ AWAS, cổng thông tin, chính phủ điện tử, phần mềm quản lý điểm, quản lý sinh viên, http://awas.vn, http://awas.com.vn, phần mềm ứng dụng, dịch vụ công trực tuyến, thiết kế website, thiet ke web, thiết kế web, điện lực, phần mềm quản lý đào tạo, cao đẳng, đại học,cổng thông tin tích hợp, cổng thông tin điện tử, webportal, thư viện điện tử, electric library, library online, email, web, quản lý quan hệ khách hàng, CRM, dịch vụ công trực tuyến, phần mềm hành chính một cửa,