Creativity and Innovation

Just another weblog

Java Windows Authentication

Leave a comment

To do Windows Authenticate in java you need jna.jar and platrofm.jar library

Below code is useful to do authentication

import com.sun.jna.platform.win32.Advapi32;
import com.sun.jna.platform.win32.Kernel32;
import com.sun.jna.platform.win32.WinBase;
import com.sun.jna.platform.win32.WinNT;

public class AuthWindowsUser {

public static void main(String[] args) {
boolean isWindowsUser=false;

isWindowsUser= authWindowsUser(“A563627″,””,”test@Pass123″);
if(isWindowsUser) {
System.out.println(“User is authenticated”);
} else {
System.out.println(“User is not authenticated”);

public static boolean authWindowsUser(String user, String domain, String password) {
WinNT.HANDLEByReference handle = new WinNT.HANDLEByReference();
boolean successful = Advapi32.INSTANCE.LogonUser(user, domain, password,WinBase.LOGON32_LOGON_NETWORK,WinBase.LOGON32_PROVIDER_DEFAULT, handle);
if (successful) {
return successful;



Author: Ganesh

Ganesh Bhagat

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s