Tuesday, April 28, 2009

Authenticate the logged on windows user

string userId = Environment.UserName;

public class Authenticate
{
[DllImport("SenaInet.dll")]
static extern int getAuthToken (string tokentype, StringBuilder tokenbuf,ref long tokenbuflen, StringBuilder idbuf, ref long idbuflen);

public static string UserToken()
{
String tokenType = "ldap";
String userid;
String token;
int retcode = 0;
long tbuflen = 16000;
StringBuilder tbuf = new StringBuilder (Convert.ToInt32 (tbuflen));
long ibuflen = 16000;
StringBuilder ibuf = new StringBuilder (Convert.ToInt32 (ibuflen));
retcode = getAuthToken(tokenType,tbuf,ref tbuflen,ibuf,ref ibuflen);
token = tbuf.ToString();
return token;
}
}

No comments: