Data Access Worldwide Knowledge Base
Article ID 2258 Article Title HOWTO: Create a login dialog for your Windows application Article URL http://www.dataaccess.com/kbasepublic/KBPrint.asp?ArticleID=2258 KBase Category VDF (GENERAL) Date Created 11/08/2006 Last Edit Date 06/01/2009
Article Text
QUESTION:
I would like to have a login dialog in my application so that a user first has to enter his user(login)name and then the password. How do I do that?
ANSWER:
You create a dialog in your workspace for accepting the values. Since revision 10.1 the product has a template that you can use to do this. The template file is called PasswordDialog.tpl. Select this one from the Create|New Dialog panel and you have a start. The dialog has a form in which the user can enter the username and one for the password. When the user clicks the OK button a routine is called to check the validity. The code in there needs to be written by you since username and password detail information will differ from system to system.
For this KB item I made a dialog in the order entry example. I used the start described above and changed the classname of the dialog from ModalPanel to dbModalPanel. Then I added a DDO for the USERS table to the dialog (via add DDO). The users table is part of this workspace and used by the web application example.
The next step I took was adding a property called pbLoggedIn which can be queried to find out if the user did complete the login completely. This property I set in the function Validate_UserInformation (which was added by the template). The code there is now:
Function Validate_UserInformation Returns Boolean
Boolean bValid
String sUserID sPwd
Date dToday
// Get and Validate user id
Get Value of oUserIDForm to sUserID
// Get and Validate password
Get Value of oPwdForm to sPwd
Send Clear Of Users_DD
Move sUserId To Users.Loginname
Send Find Of Users_DD Eq 1 // Index on LoginName
If (Found) Begin
Move (Users.Password = sPwd) To bValid
If (bValid) Begin
Sysdate dToday
Set Field_Changed_Value Of Users_DD Field Users.Last_login To dToday
Send Request_Save Of Users_DD
End
End
Function_return bValid
End_Function
Thie method will be called from the OK button's OnClick event which contains in my dialg the following information:
Procedure OnClick
Boolean bOK
// Check if the user did enter the right username and password
get Validate_UserInformation to bOK
Set pbLoggedIn To bOk
If (bOk) Begin
Send Info_Box ("Welcome" * Users.Full_name)
Send Close_Panel
End
Else Begin
Send Stop_Box "Username and/or password not correct"
End
End_Procedure // OnClick
Finally I modified the Popup_Modal method of the dialog to (re)set the pbLoggedIn property to false so that you can only have a pbLoggedIn set to true when username and password match. As extra the routine changes the number of characters the user can enter in the two form objects.
Procedure Popup_Modal
Integer iField iLength
Set pbLoggedIn To False
Get_FieldNumber Users.Loginname To iField
Get_Attribute DF_FIELD_LENGTH Of Users.File_number iField To iLength
Set Form_Margin Of oUserIDForm To iLength
Get_FieldNumber Users.Password To iField
Get_Attribute DF_FIELD_LENGTH Of Users.File_number iField To iLength
Set Form_Margin Of oPwdForm To iLength
Forward Send Popup_Modal
End_Procedure
How to use the dialog? If you add the following code to the order.src just before the start_ui statement you get the dialog activated and the username and password checked.
// open Order Entry view on application startup
Procedure LoginUser
Boolean bLoggedIn
Handle hoClient
Get Client_Id Of oMain To hoClient
Send Popup_Modal Of (oPasswordDialog (hoClient))
Get pbLoggedIn Of (oPasswordDialog (hoClient)) To bLoggedIn
If (Not (bLoggedIn)) Begin
Abort
End
End_Procedure // LoginUser
Send LoginUser
Send Activate_oOrderEntryView of (oClientArea(oMain))
Start_UI
NOTE: The above code assumes the Login.Dg was USEd inside the ClientArea object. If it is somewhere else you need to adjust the object references in the LoginUser code.
Contributed By:
Vincent Oorsprong
Company: Data Access Worldwide
email: vincent.oorsprong@dataaccess.eu
Web Site: http://www.dataaccess.eu
Web Links Related to this Article
File login.dg
URL=http://www.dataaccess.com/KBasePublic/Files/2258.login.zip
Email this Article
Email this Article to a Colleague
Send Feedback on this Article to Data Access Worldwide
Copyright ©2010 Data Access Corporation. All rights reserved.
The information provided in the Data Access Technical Knowledge Base is provided "as is" without warranty of any kind. Data Access Corporation disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. In no event shall Data Access Corporation or its suppliers be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages, even if Data Access Corporation or its suppliers have been advised of the possibility of such damages. Some states do not allow the exclusion or limitation of liability for consequential or incidental damages so the foregoing limitation may not apply.