File: w_main.srw
Size: 5168
Date: Mon, 31 Dec 2018 21:14:39 +0100
$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type st_2 from statictext within w_main
end type
type st_1 from statictext within w_main
end type
type sle_password from singlelineedit within w_main
end type
type sle_userid from singlelineedit within w_main
end type
type cb_validate from commandbutton within w_main
end type
type cb_cancel from commandbutton within w_main
end type
end forward

global type w_main from window
integer width = 1289
integer height = 592
boolean titlebar = true
string title = "Validate Windows Logon"
boolean controlmenu = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
st_2 st_2
st_1 st_1
sle_password sle_password
sle_userid sle_userid
cb_validate cb_validate
cb_cancel cb_cancel
end type
global w_main w_main

type prototypes
Function ulong WNetGetUser( &
   string lpname, &
   ref string lpusername, &
   ref ulong buflen &
   ) Library "mpr.dll" Alias For "WNetGetUserW"

Function boolean LogonUser ( &
   string lpszUsername, &
   string lpszDomain, &
   string lpszPassword, &
   ulong dwLogonType, &
   ulong dwLogonProvider, &
   ref ulong phToken &
   ) Library "advapi32.dll" Alias For "LogonUserW"

Function boolean CloseHandle ( &
   ulong hObject &
   ) Library "kernel32.dll"

end prototypes
on w_main.create
this.st_2=create st_2
this.st_1=create st_1
this.sle_password=create sle_password
this.sle_userid=create sle_userid
this.cb_validate=create cb_validate
this.cb_cancel=create cb_cancel
this.Control[]={this.st_2,&
this.st_1,&
this.sle_password,&
this.sle_userid,&
this.cb_validate,&
this.cb_cancel}
end on

on w_main.destroy
destroy(this.st_2)
destroy(this.st_1)
destroy(this.sle_password)
destroy(this.sle_userid)
destroy(this.cb_validate)
destroy(this.cb_cancel)
end on

event open;String ls_userid
Ulong lul_result, lul_buflen

lul_buflen = 32
ls_userid = Space(lul_buflen)

lul_result = WNetGetUser("", ls_userid, lul_buflen)

If lul_result = 0 Then
   sle_userid.text = ls_userid
   sle_password.SetFocus()
End If

end event

type st_2 from statictext within w_main
integer x = 37
integer y = 176
integer width = 288
integer height = 64
integer textsize = -8
integer weight = 700
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_main
integer x = 41
integer y = 48
integer width = 206
integer height = 64
integer textsize = -8
integer weight = 700
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Userid:"
boolean focusrectangle = false
end type

type sle_password from singlelineedit within w_main
integer x = 402
integer y = 168
integer width = 809
integer height = 84
integer taborder = 20
integer textsize = -8
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_userid from singlelineedit within w_main
integer x = 402
integer y = 40
integer width = 809
integer height = 84
integer taborder = 10
integer textsize = -8
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_validate from commandbutton within w_main
integer x = 37
integer y = 352
integer width = 334
integer height = 100
integer taborder = 30
integer textsize = -8
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "Validate"
boolean default = true
end type

event clicked;Constant ULong LOGON32_LOGON_NETWORK = 3
Constant ULong LOGON32_PROVIDER_DEFAULT = 0
String ls_domain, ls_username, ls_password
ULong lul_token
Boolean lb_result

ls_domain   = ""
ls_username = sle_userid.text
ls_password = sle_password.text

lb_result = LogonUser( ls_username, ls_domain, &
                  ls_password, LOGON32_LOGON_NETWORK, &
                  LOGON32_PROVIDER_DEFAULT, lul_token )
If lb_result Then
   CloseHandle(lul_token)
   MessageBox(Parent.title, "The userid/password is valid!")
Else
   MessageBox(Parent.title, "The userid/password is not valid!")
End If

end event

type cb_cancel from commandbutton within w_main
integer x = 878
integer y = 352
integer width = 334
integer height = 100
integer taborder = 40
integer textsize = -8
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;Close(Parent)

end event