Re: Windows Authentication

  •  04-19-2005, 10:42 AM

    Re: Windows Authentication

    Yes , you can .
    You must implement two classes and register it using the CuteChatConfig.exe

    for the CuteSoft.Chat.UserAdapter.GetUserUniqueName()
    you could
    return System.Security.Principal.WindowsIdentity.GetCurrent().Name
     
    for the CuteSoft.Chat.DataProvider.ListUserUniqueName() and other methods 
     , you need to use the ActiveDirectory API to list the windows members .


    (I wrote one for the 1.1 before , here is the code )
    namespace CuteChat.WinAuthLib { using System; using System.Collections; using System.Collections.Specialized; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.DirectoryServices; using CuteChat; using CuteChat.SqlServer; public class WinAuthDataProvider : SqlDataProvider { public WinAuthDataProvider(string connectionstring):base(connectionstring) { } private DirectoryEntry OpenPath() { NameValueCollection appSettings=ConfigurationSettings.AppSettings; //WinNT: case sensitive //"WinNT://." , WinNT://DOMAIN/SERVER , WinNT://WORKGROUP/PCNAME string path=appSettings["WinAuthPath"]; string username=appSettings["WinAuthUsername"]; string password=appSettings["WinAuthPassword"]; if(path==null)path="WinNT://.";//local if(username==null) return new DirectoryEntry(path); return new DirectoryEntry(path,username,password); } public override string[] ListUserUniqueName() { ArrayList names=new ArrayList(); using(DirectoryEntry nt=OpenPath()) { foreach(DirectoryEntry child in nt.Children) { if(child.SchemaClassName=="User") { names.Add(child.Properties["Name"].Value); } } } return (string[])names.ToArray(typeof(string)); } public override UserInfoData GetUserInfo(string useruniquename) { using(DirectoryEntry nt=OpenPath()) { foreach(DirectoryEntry child in nt.Children) { if(child.SchemaClassName=="User") { string name=Convert.ToString(child.Properties["Name"].Value); if(string.Compare(name,useruniquename,true)==0) { bool isadmin=string.Compare(useruniquename,ConfigurationSettings.AppSettings["AdminLoginName"],true)==0; string fullname=Convert.ToString(child.Properties["FullName"].Value); if(fullname==null||fullname.Length==0) fullname=name; return new UserInfoData(useruniquename,fullname,isadmin); } } } } throw(new Exception("User not found")); } public override bool IsUserNickNameExists(string nickname) { using(DirectoryEntry nt=OpenPath()) { foreach(DirectoryEntry child in nt.Children) { if(child.SchemaClassName=="User") { string name=Convert.ToString(child.Properties["Name"].Value); string full=Convert.ToString(child.Properties["FullName"].Value); if(string.Compare(name,nickname,true)==0) return true; if(string.Compare(full,nickname,true)==0) return true; } } } return false; } } }

    Today I am busy , please wait , I will write one two days later .
     
    Regards , Terry .
View Complete Thread