1. Avory Rose Pastoral
  2. PowerBuilder
  3. Friday, 2 September 2022 06:55 AM UTC

I have an application that needs an LDAP (Active Directory) login. In my previous project I have managed to create an application that has LDAP login. I created it using webservice but I am not quiet happy with its speed. Sometimes, it takes 1 minute before it successfully login. Does anyone here have an idea how to create LDAP login that connects directly to ldap / ldap dll without connecting to webservice? By the way I am using Powerbuilder 2019.

Any idea would be very much appreciated.

Thank you so much

Accepted Answer
PowerObject ! Accepted Answer Pending Moderation
  1. Wednesday, 7 September 2022 05:52 AM UTC
  2. PowerBuilder
  3. # Permalink

Attaching the zipped file. Just uncompress it and import the files (n_cst_login.sru first followed by w_Login) into your library and add the code to Open( w_Login ).

Login using LDAP or Active Directory takes just about 2 seconds for the first time and less than a second subsequently.

Attachments (1)
Comment
  1. PowerObject !
  2. Thursday, 8 September 2022 18:09 PM UTC
Updated with more screenshots. See below...
  1. Helpful
  1. Avory Rose Pastoral
  2. Monday, 19 September 2022 06:57 AM UTC
Hello sir when I put my exe on server and access it, it takes 1 or 2 minutes before the login window will load. Do you have any idea what seems to be the problem is? Thank you.
  1. Helpful
  1. PowerObject !
  2. Monday, 19 September 2022 16:01 PM UTC
Not sure what you mean by putting exe on the server. Are you using a file-server to launch your app, PowerClient or PowerServer?



If executing over a file-server, it could be slow as usual. It is not the issue with the login logic. Run your app using a local copy of the app. Did you try running the attached app from your local machine?



If using PowerClient, the app gets sync'ed to your local machine and should be quick too.



If using PowerServer, only the backend logic gets ported into C# and deployed on to the app server. All UI logic (including LDAP/AD login) remains inside the client app and should be quick as well. Once you authenticate using Windows creds, you just connect to the dB using a common user and password (the end users won't know these dB creds stored on the app server and this logic gets deployed on to the app server)
  1. Helpful
There are no comments made yet.
Miguel Alzate Accepted Answer Pending Moderation
  1. Monday, 4 September 2023 14:10 PM UTC
  2. PowerBuilder
  3. # 1

Hi, PowerObject. I've tried succesfully your LDAP code. Thanks a lot! Once succesfully connected to the LDAP server, how to make querys for specific users to check they're valid ones?

Comment
There are no comments made yet.
PowerObject ! Accepted Answer Pending Moderation
  1. Thursday, 8 September 2022 18:21 PM UTC
  2. PowerBuilder
  3. # 2

Updated with more screenshots. See below...

Comment
There are no comments made yet.
PowerObject ! Accepted Answer Pending Moderation
  1. Monday, 5 September 2022 18:44 PM UTC
  2. PowerBuilder
  3. # 3

Attaching w_Login.txt (rename this to .srw) and n_cst_Login.txt (rename this to .sru) with options to perform LDAP and Active Directory logins. The code is exported from PowerBuilder 2017 for forward compatibility during import into later versions. The login window is implemented using non-intrusive status messages for better UX.

Once login is successful using network creds, go ahead and connect to the dB implicitly using a common dB User with sufficient privileges (especially useful in 3-Tier PowerServer apps and SSO).

If you make too many unsuccessful login attempts, you could get locked out of Windows!

For 2-Tier dB login, you could disable the Domain SLE (or replace it with a DDLB of databases) and use the Username and Password fields to directly log into the dB by altering some logic in of_Login().

On PowerBuilder 2022, window size is messed up - re-align the controls and status bar as needed.

Ignore the functions starting with xf_* or discard them.

There is a Themes DDLB too on the login screen - uncomment the ApplyTheme() call in of_ApplyTheme() if using PowerBuilder 2019 or later, if needed.

Assign logo, image and modify the Copyright text.

For people with color blindness, adjust the UI colors.

Hello Appeon, we cannot attach .srw or .sru or any PowerBuilder source files? Not even TXT files?

 

 

 

 

 

 

N_CST_LOGIN

$PBExportHeader$n_cst_login.sru
$PBExportComments$SHEKAR
forward
global type n_cst_login from nonvisualobject
end type
end forward

global type n_cst_login from nonvisualobject autoinstantiate
end type

type prototypes
// This function gets the network login userid
//Function ulong WNetGetUser(string lpname, ref string lpusername, ref ulong buflen) Library "mpr.dll" Alias For "WNetGetUserA;Ansi"

// This function validates the login userid/password
Function boolean LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, ulong dwLogonType, ulong dwLogonProvider, ref ulong phToken) Library "advapi32.dll" Alias For "LogonUserA;Ansi"
//Function boolean LogonUserEx(string lpszUsername, string lpszDomain, string lpszPassword, ulong dwLogonType, ulong dwLogonProvider, ref ulong phToken) Library "advapi32.dll" Alias For "LogonUserExA;Ansi"

// Close the connection
Function boolean CloseHandle(ulong hObject) Library "kernel32.dll"

end prototypes

type variables
CONSTANT ULong LOGON32_LOGON_NETWORK = 3
CONSTANT ULong LOGON32_PROVIDER_DEFAULT = 0
//
CONSTANT integer C_LOGIN_SUCCESS = 1
CONSTANT integer C_LOGIN_FAILURE = 0
CONSTANT integer C_LOGIN_ERROR_USERNAME = -1
CONSTANT integer C_LOGIN_ERROR_PASSWORD = -2
CONSTANT integer C_LOGIN_ERROR_DOMAIN = -3
//
CONSTANT string C_LOGIN_SUCCESS_MESSAGE = "Login successful"
CONSTANT string C_LOGIN_FAILURE_MESSAGE = "Incorrect Username or Password"
CONSTANT string C_LOGIN_ERROR_USERNAME_MESSAGE = "Username cannot be blank"
CONSTANT string C_LOGIN_ERROR_PASSWORD_MESSAGE = "Password cannot be blank"
CONSTANT string C_LOGIN_ERROR_DOMAIN_MESSAGE = "Domain cannot be blank"

end variables

forward prototypes
public function integer of_loginad (string as_username, string as_password, string as_domain)
public function integer of_loginldap (string as_username, string as_password, string as_domain)
public function integer of_getdetails (ref string as_username, ref string as_domain, ref string as_computername)
public function string xf_getdomain ()
public function string xf_getusername ()
public function integer of_validate (string as_username, string as_password, string as_domain)
public function integer xf_validate (string as_username, string as_password, string as_domain)
end prototypes

public function integer of_loginad (string as_username, string as_password, string as_domain);// SHEKAR - ActiveDirectory Authentication
uLong lul_Result, lul_BufferLength, lul_Token
integer li_Return
boolean lb_Result
//
li_Return = of_Validate( as_Username, as_Password, as_Domain )
//
IF li_Return <= 0 THEN
RETURN li_Return // Error with credentials
END IF
//
lb_Result = LogonUser( as_Username, as_Domain, as_Password, LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, lul_Token )
//
IF lb_Result THEN
CloseHandle( lul_Token )
RETURN C_LOGIN_SUCCESS // Login Success
END IF
//
RETURN C_LOGIN_FAILURE // Login Failure

end function

public function integer of_loginldap (string as_username, string as_password, string as_domain);// // SHEKAR - LDAP Authentication
uLong lul_Result, lul_BufferLength, lul_Token
integer li_Return
boolean lb_result
string ls_Code, ls_Eval
OLEObject ole_Wsh
//
li_Return = of_Validate( as_Username, as_Password, as_Domain )
//
IF li_Return <= 0 THEN
RETURN li_Return
END IF
//
// Define VBScript
ls_Code = 'Function Logon()~r~n' &
+ 'const ADS_SECURE_AUTHENTICATION = &h0001~r~n' &
+ 'const ADS_CHASE_REFERRALS_ALWAYS = &H60~r~n' &
+ 'strDomain = "' + as_Domain + '"~r~n' &
+ 'strUserID = "' + as_Username + '"~r~n' &
+ 'strUserPWD = "' + as_Password + '"~r~n' &
+ 'strPath = "LDAP://" & strDomain & "/OU=Users,DC=" & strDomain~r~n' &
+ 'On Error Resume Next~r~n' &
+ 'set objDSO = GetObject("LDAP:")~r~n' &
+ 'set objUser = objDSO.OpenDSObject(strPath, strUserID, strUserPWD, ADS_SECURE_AUTHENTICATION OR ADS_CHASE_REFERRALS_ALWAYS)~r~n' &
+ 'if Err.Number <> 0 then~r~n' &
+ ' Logon = False~r~n' &
+ 'else~r~n' &
+ ' Logon = True~r~n' &
+ 'end if~r~n' &
+ 'Err.Clear~r~n' &
+ 'On Error Goto 0~r~n' &
+ 'set objDSO = Nothing~r~n' &
+ 'set objUser = Nothing~r~n' &
+ 'end function'
//
li_Return = C_LOGIN_FAILURE // Init - Login failure
//
TRY
//
ole_Wsh = CREATE OLEObject
ole_Wsh.ConnectToNewObject( 'MSScriptControl.ScriptControl' )
//
// Set the VBScript
ole_Wsh.Language = 'VBScript'
ole_Wsh.AddCode( ls_Code )
//
// Run the function
ls_Eval = Lower( String( ole_Wsh.Eval( 'Logon' )))
//
IF ls_Eval = 'true' THEN
li_Return = C_LOGIN_SUCCESS
// GOTO HELL
END IF
//
CATCH ( Exception e )
MessageBox( 'Error', e.GetMessage())
END TRY
//
//////////////////////////
//HELL:
//////////////////////////
ole_Wsh.DisconnectObject()
DESTROY ole_Wsh
GarbageCollect()
//
RETURN li_Return

end function

public function integer of_getdetails (ref string as_username, ref string as_domain, ref string as_computername);// SHEKAR - Get Network details
integer li_Result
OLEObject ole_Wsh
//
ole_Wsh = CREATE OLEObject
li_Result = ole_Wsh.ConnectToNewObject( 'WScript.Network' )
//
IF li_Result = 0 THEN
as_Username = ole_Wsh.UserName
as_Domain = ole_Wsh.UserDomain
as_ComputerName = ole_Wsh.ComputerName
END IF
//
ole_Wsh.DisconnectObject()
DESTROY ole_Wsh
GarbageCollect()
//
RETURN li_Result

 

/*
oleobject ads
string ls_stuff
ads = CREATE OleObject

ads.ConnectToNewObject( "ADSystemInfo" )

ls_stuff = 'User: ' + String(ads.UserName)
ls_stuff += '~n~r' + 'Computer: ' + string(ads.ComputerName)
ls_stuff += '~n~r' + 'Domain: ' + string(ads.DomainDNSName)
ls_stuff += '~n~r' + 'Domain short: ' + string(ads.DomainShortName)
ls_stuff += '~n~r' + 'Forest: ' + string(ads.ForestDNSName)
ls_stuff += '~n~r' + 'Native Mode: ' + string(ads.IsNativeMode)
ls_stuff += '~n~r' + 'PDCRoleOwner: ' + string(ads.PDCRoleOwner)
ls_stuff += '~n~r' + 'SchemaRoleOwner: ' + string(ads.SchemaRoleOwner)
ls_stuff += '~n~r' + 'Site: ' + string(ads.SiteName)


MessageBox("Active Directory - Information",ls_stuff)
DESTROY(ads)
------
ADSystemInfo interface defines the following properties. All are read only

ComputerName
Retrieves the distinguished name of the local computer.

DomainDNSName
Retrieves the DNS name of the local computer domain, for example “example.fabrikam.com”.

DomainShortName
Retrieves the short name of the local computer domain, for example “myDom”.

ForestDNSName
Retrieves the DNS name of the local computer forest.

IsNativeMode
Determines whether the local computer domain is in native or mixed mode.

PDCRoleOwner
Retrieves the distinguished name of the NTDS-DSA object for the DC that owns the primary domain controller role in the local computer domain.

SchemaRoleOwner
Retrieves the distinguished name of the NTDS-DSA object for the DC that owns the schema role in the local computer forest.

SiteName
Retrieves the site name of the local computer.

UserName
Retrieves the Active Directory distinguished name of the current user, which is the logged-on user or the user impersonated by the calling thread.
*/
end function

public function string xf_getdomain ();string ls_Domain
OLEObject LDAP
//
// Connect to ActiveDirectory
LDAP = CREATE OLEObject
LDAP.ConnectToNewObject( "ADSystemInfo" )
//*/
// Get the Domain
TRY
ls_Domain = String( LDAP.DomainDNSName )
CATCH ( Exception e )
MessageBox( 'Error', e.GetMessage())
ls_Domain = ''
END TRY
//
LDAP.DisconnectObject()
DESTROY LDAP
GarbageCollect()
//
RETURN ls_Domain

/*
FUNCTION long GetEnvironmentVariableA(string varname,REF
string lpszResultBuffer,long nBufferSize) LIBRARY
'kernel32.dll'

Put the following code wherever you want to :

string s_env
Long ll_ret
string s_buffer
Long ll_size

s_env = "USERDNSDOMAIN"
s_buffer= space(256)
ll_size= 50
ll_ret= GetEnvironmentVariableA(s_env, s_buffer, ll_size)

MessageBox("USERDNSDOMAIN",s_buffer)
=====================================

OLEObject l_ole
int li_rc
string ls_domain, ls_user, ls_site, ls_computername

l_ole = CREATE OLEObject
li_rc = l_ole.ConnectToNewObject( "ADSystemInfo")

IF li_rc = 0 THEN
ls_computername = l_ole.computername //CN=CAL26040,OU=Computers,OU=calgary,DC=forestoil,DC=com
ls_site = l_ole.sitename // calgary
ls_user = l_ole.username // CN=Terry Dykstra(tddykstra),OU=Users,OU=calgary,DC=forestoil,DC=com
ls_domain = l_ole.domaindnsname // forestoil.com
END IF

l_ole.DisConnectObject()
DESTROY l_ole
*/
end function

public function string xf_getusername ();string ls_Username
uLong lul_Result, lul_BufferLength
//
// Get the username
lul_BufferLength = 32
ls_Username = Space( lul_BufferLength )
//lul_Result = WNetGetUser( '', ls_Username, lul_BufferLength )
//
IF lul_Result = 0 THEN
RETURN ls_Username
END IF
//
RETURN ''


/*
PUBLIC FUNCTION Boolean GetUserNameA(REF string user, REF ulong size)
LIBRARY "ADVAPI32.DLL"

Power Script:

ulong lul_size = 255
string ls_username = space(lul_size)

IF NOT GetUserNameA( ls_username, lul_size) THEN
SetNull(ls_username)
END IF

RETURN ls_username
*/
end function

public function integer of_validate (string as_username, string as_password, string as_domain);// SHEKAR - LDAP Authentication
string ls_User, ls_Dom, ls_Computer
boolean lb_Invoked
//
as_Username = Trim( as_Username )
as_Domain = Trim( as_Domain )
// NO TRIMMING of the as_Password
//
// Validate login creds
IF IsNull( as_Username ) OR as_Username = '' THEN
RETURN C_LOGIN_ERROR_USERNAME // No Username
ELSEIF IsNull( as_Password ) OR as_Password = '' THEN
RETURN C_LOGIN_ERROR_PASSWORD // No Password
ELSEIF IsNull( as_Domain ) OR as_Domain = '' THEN
RETURN C_LOGIN_ERROR_DOMAIN // No Domain
END IF
//
RETURN 1 // All clear

end function

public function integer xf_validate (string as_username, string as_password, string as_domain);// SHEKAR - LDAP Authentication
string ls_User, ls_Dom, ls_Computer
boolean lb_Invoked
//
IF IsNull( as_Password ) OR as_Password = '' THEN
RETURN C_LOGIN_ERROR_PASSWORD // No password
END IF
//
as_Username = Trim( as_Username )
as_Domain = Trim( as_Domain )
//
// Get the username
IF IsNull( as_Username ) OR as_Username = '' THEN
//
RETURN C_LOGIN_ERROR_USERNAME // Username error
/*
of_GetDetails( ls_User, ls_Dom, ls_Computer )
lb_Invoked = TRUE
as_Username = ls_User
//
IF as_Username = '' THEN
RETURN C_LOGIN_ERROR_USERNAME // Username error
END IF
*/
//
END IF
//
// Get the Domain
IF IsNull( as_Domain ) OR as_Domain = '' THEN
//
RETURN C_LOGIN_ERROR_DOMAIN // Domain error
/*
IF NOT lb_Invoked THEN
of_GetDetails( ls_User, ls_Dom, ls_Computer )
lb_Invoked = TRUE
END IF
//
as_Domain = ls_Dom
//
IF as_Domain = '' THEN
RETURN C_LOGIN_ERROR_DOMAIN // Domain error
END IF
*/
//
END IF
//
RETURN 1 // All clear

 

/*
IF as_Password = '' THEN
RETURN -2 // No password
END IF
//
// Get the username
IF as_Username = '' THEN
//
as_Username = of_GetUsername()
//
IF as_Username = '' THEN
RETURN -1 // Username error
END IF
//
END IF
//
// Get the Domain
IF as_Domain = '' THEN
//
as_Domain = of_GetDomain()
//
IF as_Domain = '' THEN
RETURN -3 // Domain error
END IF
//
END IF
//
RETURN 1 // All clear
*/
end function

on n_cst_login.create
call super::create
TriggerEvent( this, "constructor" )
end on

on n_cst_login.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

 

W_LOGIN

$PBExportHeader$w_login.srw
$PBExportComments$SHEKAR
forward
global type w_login from window
end type
type cbx_showpassword from checkbox within w_login
end type
type cb_resetdomain from commandbutton within w_login
end type
type cb_username from commandbutton within w_login
end type
type ddlb_theme from dropdownlistbox within w_login
end type
type st_4 from statictext within w_login
end type
type st_status from statictext within w_login
end type
type mle_copyright from multilineedit within w_login
end type
type p_logo from picture within w_login
end type
type p_login from picture within w_login
end type
type cb_ad from commandbutton within w_login
end type
type cb_cancel from commandbutton within w_login
end type
type st_3 from statictext within w_login
end type
type sle_domain from singlelineedit within w_login
end type
type st_2 from statictext within w_login
end type
type st_1 from statictext within w_login
end type
type sle_password from singlelineedit within w_login
end type
type sle_username from singlelineedit within w_login
end type
type cb_ldap from commandbutton within w_login
end type
type ln_1 from line within w_login
end type
type ln_2 from line within w_login
end type
type ln_3 from line within w_login
end type
type ln_4 from line within w_login
end type
end forward

global type w_login from window
integer width = 2039
integer height = 1160
boolean titlebar = true
string title = "Login"
windowtype windowtype = response!
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
cbx_showpassword cbx_showpassword
cb_resetdomain cb_resetdomain
cb_username cb_username
ddlb_theme ddlb_theme
st_4 st_4
st_status st_status
mle_copyright mle_copyright
p_logo p_logo
p_login p_login
cb_ad cb_ad
cb_cancel cb_cancel
st_3 st_3
sle_domain sle_domain
st_2 st_2
st_1 st_1
sle_password sle_password
sle_username sle_username
cb_ldap cb_ldap
ln_1 ln_1
ln_2 ln_2
ln_3 ln_3
ln_4 ln_4
end type
global w_login w_login

type prototypes
// This function gets the network login userid
Function ulong WNetGetUser(string lpname, ref string lpusername, ref ulong buflen) Library "mpr.dll" Alias For "WNetGetUserA;Ansi"

// This function validates the login userid/password
Function boolean LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, ulong dwLogonType, ulong dwLogonProvider, ref ulong phToken) Library "advapi32.dll" Alias For "LogonUserA;Ansi"
//Function boolean LogonUserEx(string lpszUsername, string lpszDomain, string lpszPassword, ulong dwLogonType, ulong dwLogonProvider, ref ulong phToken) Library "advapi32.dll" Alias For "LogonUserExA;Ansi"

// Close the connection
Function boolean CloseHandle(ulong hObject) Library "kernel32.dll"

end prototypes

type variables
// SHEKAR - LDAP Authentication
CONSTANT long C_COLOR_RED = RGB( 192, 0, 0 )
CONSTANT long C_COLOR_GREEN = RGB( 0, 128, 0 )
CONSTANT long C_COLOR_YELLOW = RGB( 255, 255, 0 )
//
n_cst_Login inv_Login
string is_Theme
string is_Username, is_Domain, is_Computer
end variables

forward prototypes
public function integer of_login (string as_type)
public function integer of_applytheme ()
end prototypes

public function integer of_login (string as_type);// SHEKAR - LDAP Authentication
integer li_Result
long ll_Color
string ls_Username, ls_Password, ls_Domain, ls_Message
singleLineEdit lsle_Control
//
SetPointer( HourGlass! )
as_Type = Upper( Trim( as_Type ))
//
IF as_Type = '' THEN
as_Type = 'LDAP'
END IF
//
ls_Username = sle_Username.Text
ls_Password = sle_Password.Text
ls_Domain = sle_Domain.Text
//
st_Status.Text = " Please wait..."
st_Status.TextColor = 0 // Black
st_Status.BackColor = C_COLOR_YELLOW
//
IF as_Type = 'LDAP' THEN
li_Result = inv_Login.of_LoginLDAP( ls_Username, ls_Password, ls_Domain )
ELSEIF as_Type = 'AD' THEN
li_Result = inv_Login.of_LoginAD( ls_Username, ls_Password, ls_Domain )
ELSE
li_Result = inv_Login.C_LOGIN_FAILURE
END IF
//
IF li_Result > 0 THEN // 1
ll_Color = C_COLOR_GREEN
ls_Message = inv_Login.C_LOGIN_SUCCESS_MESSAGE
// TODO: Go ahead and login into the database "implicitly", now...
ELSE
//
Beep( 1 ) // Audible error
ll_Color = C_COLOR_RED
//
IF li_Result = inv_Login.C_LOGIN_ERROR_USERNAME THEN // -1
ls_Message = inv_Login.C_LOGIN_ERROR_USERNAME_MESSAGE
lsle_Control = sle_Username
ELSEIF li_Result = inv_Login.C_LOGIN_ERROR_PASSWORD THEN // -2
ls_Message = inv_Login.C_LOGIN_ERROR_PASSWORD_MESSAGE
lsle_Control = sle_Password
ELSEIF li_Result = inv_Login.C_LOGIN_ERROR_DOMAIN THEN // -3
ls_Message = inv_Login.C_LOGIN_ERROR_DOMAIN_MESSAGE
lsle_Control = sle_Domain
ELSE // 0
ls_Message = inv_Login.C_LOGIN_FAILURE_MESSAGE
lsle_Control = sle_Username
END IF
//
END IF
//
st_Status.Text = ' ' + ls_Message
st_Status.BackColor = ll_Color
st_Status.TextColor = C_COLOR_YELLOW
//
// Set focus to the right edit control for user-friendliness :)
IF IsValid( lsle_Control ) THEN
lsle_Control.SetFocus()
END IF
//
RETURN li_Result

end function

public function integer of_applytheme ();// SHEKAR - UI Themes
// Valid values: dark, blue, grey or gray, silver
// gnv_App.of_GetTheme()
// Upper( Trim( ProfileString( gnv_App.is_IniFile, 'GENERAL','THEME', '' )))
is_Theme = Upper( Trim( ddlb_Theme.Text )) // Or populate the DDLB with Theme folder names
//
IF is_Theme = 'DARK' THEN
is_Theme = 'Flat Design Dark'
ELSEIF is_Theme = 'BLUE' THEN
is_Theme = 'Flat Design Blue'
ELSEIF is_Theme = 'GREY' OR is_Theme = 'GRAY' THEN
is_Theme = 'Flat Design Grey'
ELSEIF is_Theme = 'SILVER' THEN
is_Theme = 'Flat Design Silver'
ELSE
is_Theme = '' // System
END IF
//
// gnv_App.of_SetTheme( is_Theme )
// Upper( Trim( SetProfileString( gnv_App.is_IniFile, 'GENERAL','THEME', is_Theme )))
//
//RETURN ApplyTheme( is_Theme ) // Uncomment for PowerBuilder 2019 and above
RETURN 1

end function

on w_login.create
this.cbx_showpassword=create cbx_showpassword
this.cb_resetdomain=create cb_resetdomain
this.cb_username=create cb_username
this.ddlb_theme=create ddlb_theme
this.st_4=create st_4
this.st_status=create st_status
this.mle_copyright=create mle_copyright
this.p_logo=create p_logo
this.p_login=create p_login
this.cb_ad=create cb_ad
this.cb_cancel=create cb_cancel
this.st_3=create st_3
this.sle_domain=create sle_domain
this.st_2=create st_2
this.st_1=create st_1
this.sle_password=create sle_password
this.sle_username=create sle_username
this.cb_ldap=create cb_ldap
this.ln_1=create ln_1
this.ln_2=create ln_2
this.ln_3=create ln_3
this.ln_4=create ln_4
this.Control[]={this.cbx_showpassword,&
this.cb_resetdomain,&
this.cb_username,&
this.ddlb_theme,&
this.st_4,&
this.st_status,&
this.mle_copyright,&
this.p_logo,&
this.p_login,&
this.cb_ad,&
this.cb_cancel,&
this.st_3,&
this.sle_domain,&
this.st_2,&
this.st_1,&
this.sle_password,&
this.sle_username,&
this.cb_ldap,&
this.ln_1,&
this.ln_2,&
this.ln_3,&
this.ln_4}
end on

on w_login.destroy
destroy(this.cbx_showpassword)
destroy(this.cb_resetdomain)
destroy(this.cb_username)
destroy(this.ddlb_theme)
destroy(this.st_4)
destroy(this.st_status)
destroy(this.mle_copyright)
destroy(this.p_logo)
destroy(this.p_login)
destroy(this.cb_ad)
destroy(this.cb_cancel)
destroy(this.st_3)
destroy(this.sle_domain)
destroy(this.st_2)
destroy(this.st_1)
destroy(this.sle_password)
destroy(this.sle_username)
destroy(this.cb_ldap)
destroy(this.ln_1)
destroy(this.ln_2)
destroy(this.ln_3)
destroy(this.ln_4)
end on

event open;// SHEKAR - LDAP Authentication
string ls_Username, ls_Domain, ls_Computer, ls_Copyright
//
ls_Copyright = mle_Copyright.Text
ls_Copyright = Mid( ls_Copyright, 7 )
ls_Copyright = '© ' + String( Year( Today())) + ls_Copyright
mle_Copyright.Text = ls_Copyright
//
inv_Login.of_GetDetails( is_Username, is_Domain, is_Computer )
//
// Initialize fields and set focus
sle_Username.Text = is_Username
sle_Domain.Text = is_Domain
//
IF sle_Username.Text <> "" THEN
sle_Password.SetFocus()
END IF

 

/*
// Initialize fields and set focus
sle_Username.Text = inv_Login.of_GetUsername()
sle_Domain.Text = inv_Login.of_GetDomain()
//
IF sle_Username.Text <> "" THEN
sle_Password.SetFocus()
END IF
*/
end event

type cbx_showpassword from checkbox within w_login
integer x = 1746
integer y = 224
integer width = 201
integer height = 68
integer taborder = 40
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
string text = "Show"
end type

event clicked;// SHEKAR
sle_Password.Password = ( NOT This.Checked)

end event

type cb_resetdomain from commandbutton within w_login
integer x = 1742
integer y = 352
integer width = 201
integer height = 80
integer taborder = 60
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Reset"
end type

event clicked;// SHEKAR
sle_Domain.Text = is_Domain

end event

type cb_username from commandbutton within w_login
integer x = 1742
integer y = 88
integer width = 201
integer height = 80
integer taborder = 20
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Reset"
end type

event clicked;// SHEKAR
sle_Username.Text = is_Username

end event

type ddlb_theme from dropdownlistbox within w_login
integer x = 1673
integer y = 876
integer width = 288
integer height = 596
integer taborder = 100
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
boolean sorted = false
string item[] = {"System","Dark","Blue","Gray","Silver"}
borderstyle borderstyle = stylelowered!
end type

event selectionchanged;of_ApplyTheme()
end event

type st_4 from statictext within w_login
integer x = 1714
integer y = 804
integer width = 251
integer height = 60
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "MS Sans Serif"
long textcolor = 33554432
long backcolor = 67108864
string text = "THEME"
boolean focusrectangle = false
end type

type st_status from statictext within w_login
integer x = 9
integer y = 996
integer width = 2011
integer height = 76
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 65535
long backcolor = 67108864
boolean focusrectangle = false
end type

type mle_copyright from multilineedit within w_login
integer x = 46
integer y = 808
integer width = 1623
integer height = 180
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Small Fonts"
long textcolor = 33554432
long backcolor = 67108864
boolean enabled = false
string text = "© 2022 PowerObject. All rights reserved."
boolean border = false
borderstyle borderstyle = stylelowered!
end type

type p_logo from picture within w_login
integer x = 69
integer y = 588
integer width = 457
integer height = 104
boolean focusrectangle = false
end type

type p_login from picture within w_login
integer width = 590
integer height = 768
boolean focusrectangle = false
end type

type cb_ad from commandbutton within w_login
integer x = 1106
integer y = 588
integer width = 402
integer height = 112
integer taborder = 80
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "AD"
end type

event clicked;// SHEKAR - LDAP Authentication
RETURN of_Login( 'AD' )

end event

type cb_cancel from commandbutton within w_login
integer x = 1550
integer y = 588
integer width = 402
integer height = 112
integer taborder = 90
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Cancel"
boolean cancel = true
end type

event clicked;// SHEKAR - LDAP Authentication
CloseWithReturn( Parent, -1 )

end event

type st_3 from statictext within w_login
integer x = 667
integer y = 356
integer width = 325
integer height = 64
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Domain:"
boolean focusrectangle = false
end type

type sle_domain from singlelineedit within w_login
integer x = 992
integer y = 344
integer width = 960
integer height = 96
integer taborder = 50
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

type st_2 from statictext within w_login
integer x = 667
integer y = 224
integer width = 325
integer height = 64
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Password:"
boolean focusrectangle = false
end type

type st_1 from statictext within w_login
integer x = 667
integer y = 88
integer width = 325
integer height = 64
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Username:"
boolean focusrectangle = false
end type

type sle_password from singlelineedit within w_login
integer x = 992
integer y = 212
integer width = 960
integer height = 96
integer taborder = 30
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
boolean password = true
borderstyle borderstyle = stylelowered!
end type

type sle_username from singlelineedit within w_login
integer x = 992
integer y = 80
integer width = 960
integer height = 96
integer taborder = 10
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
borderstyle borderstyle = stylelowered!
end type

type cb_ldap from commandbutton within w_login
integer x = 667
integer y = 588
integer width = 402
integer height = 112
integer taborder = 70
integer textsize = -10
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "LDAP"
boolean default = true
end type

event clicked;// SHEKAR - LDAP Authentication
RETURN of_Login( 'LDAP' )

end event

type ln_1 from line within w_login
long linecolor = 268435456
integer linethickness = 4
integer beginx = -50
integer beginy = 516
integer endx = 2098
integer endy = 516
end type

type ln_2 from line within w_login
long linecolor = 33554432
integer linethickness = 4
integer beginx = 585
integer beginy = -16
integer endx = 585
integer endy = 768
end type

type ln_3 from line within w_login
long linecolor = 134217749
integer linethickness = 4
integer beginx = -59
integer beginy = 768
integer endx = 2089
integer endy = 768
end type

type ln_4 from line within w_login
long linecolor = 134217744
integer linethickness = 4
integer beginx = -50
integer beginy = 992
integer endx = 2075
integer endy = 992
end type

 

Comment
  1. Avory Rose Pastoral
  2. Wednesday, 7 September 2022 00:09 AM UTC
Hello thank you very much I will try it on my end. However some instruction weren't clear to me. Would you mind sending the file via email?





Thank you.
  1. Helpful
  1. Miguel Leeuwe
  2. Wednesday, 7 September 2022 05:40 AM UTC
You could have zipped the exported files and added that as an attachment.

  1. Helpful
There are no comments made yet.
PowerObject ! Accepted Answer Pending Moderation
  1. Friday, 2 September 2022 14:35 PM UTC
  2. PowerBuilder
  3. # 4

You can do LDAP authentication using VB Script and OLE Automation inside PowerScript.

You can also do Active Directory authentication using LogonUser() API function.

You'll find the code for both the above methods online.

Comment
  1. Avory Rose Pastoral
  2. Monday, 5 September 2022 00:45 AM UTC
Hello would you mind sharing some link/s? I can't find any example. Thank you.
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.