1. radha rani
  2. PowerBuilder
  3. Tuesday, 10 April 2018 21:09 PM UTC

Hi ,

 

I have a question in which i want a simple sample code like of login page 

username : text

password:text

ok_btn

so once i clicked on ok_btn the above entered details of username and password gets saved to database.

 

Please help me with code because i didnt found an help 

 

Michael Kramer Accepted Answer Pending Moderation
  1. Wednesday, 11 April 2018 10:11 AM UTC
  2. PowerBuilder
  3. # 1

Hi Radha,

Are you sure you want to save the combination in the database?
From a security perspective you never want to save the password, not even the failed login passwords because saving it means that someone can read it later.

You may opt for embedded SQL (see previous answers to your question) or use a DataWindow object in a DataStore to save whatever login related data is needed in your particular case. I have sometimes seen the following data saved when a user logs on:

  • UserID and LoginTimestamp - because you want to audit logins
  • ApplicationID and Version - because you want to track what application logic is accessing your database

HTH /Michael

Comment
  1. radha rani
  2. Wednesday, 11 April 2018 17:03 PM UTC
Hi Michael,



I just want to learn how to connect to db and save data by creatig one sample program .



But i am facing error in above code database error.

  1. Helpful
  1. David Peace (Powersoft)
  2. Thursday, 12 April 2018 16:27 PM UTC
Can I suggest that you do the PB tutorial as this will get you started with the basics. https://www.appeon.com/sites/default/files/product-manual/users_guide_for_pb.pdf



This is the best way to understand the concepts for PB.



Regards



David

  1. Helpful
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 11 April 2018 00:20 AM UTC
  2. PowerBuilder
  3. # 2

Hi Radharani,

 

Here's a sample code for saving data to the database:

 

//************************************************************

// Variable Declarations

//************************************************************

STRING ls_username

STRING ls_password

INTEGER li_count

 

//We Initialize the variables by trimming blank spaces from the Single Line Edit Controls

ls_username = TRIM(sle_username.text)

ls_password = TRIM(sle_password.text)

 

//************************************************************

// Logic of the Script

//************************************************************

//Insert the values into the Database

INSERT INTO USERS (USER_ID, USERNAME, PASSWORD)

VALUES (123, :ls_username, :ls_password)

USING SQLCA;

 

//Check for any database errors

IF SQLCA.SQLCODE <> 0 THEN

   //If an error: notify the user

   MessageBox("Database Error!", "Error while saving data to the database. Error message: [" + STRING(SQLCA.SQLCODE) + "] - " + SQLCA.SQLERRTEXT)

 

ELSE

   //If everything OK, Notify the user

   MessageBox("Data saved!", "The data has been successfully saved to the database!")

END IF

 

Remember: It's always good practice to check if the data already exists before saving it.

 

Regards,

Comment
  1. radha rani
  2. Wednesday, 11 April 2018 15:27 PM UTC
Hi Govinda,



Thanks for the code.



I have tried your code but its showing error database can you please help me with the error what needs to be checked.

  1. Helpful
  1. radha rani
  2. Wednesday, 11 April 2018 20:35 PM UTC
Thanks done!!



Need to add sqlca db connection also..

  1. Helpful
There are no comments made yet.
Govinda Lopez @Appeon Accepted Answer Pending Moderation
  1. Tuesday, 10 April 2018 21:42 PM UTC
  2. PowerBuilder
  3. # 3

Hi Radharani,

 

This is a very simple sample code of login button:

 

STRING ls_username

STRING ls_password

INTEGER li_count

 

ls_username = TRIM(sle_username.Text)

ls_password = TRIM(sle_password.Text)

 

SELECT COUNT(*)

INTO :li_count

FROM USERS

WHERE USER_ID = :ls_username

AND PASSWORD = :ls_password

USING SQLCA;

 

IF li_count = 1 THEN

   Open(w_test)

ELSE

   MessageBox("Warning!", "The Username and/or password is invalid! Try again.")

END IF

 
I hope it helps.
 
 
Regards,
Comment
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.