Creating Login screen from SQL Problem

Creating desktop or client-server database solutions?

Moderators: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Creating Login screen from SQL Problem

Post by Jamie37 » Thu Dec 24, 2015 5:36 pm

Hello,

I have followed a previous post on the forum from a different member who was having issues that would could livecode to show incorrect password even though the inputs on the two input field (Username & Password) matched the ones in database. I have gone through the posts and every suggestion I tried it still gives me a false return. Below is the code i'm using and I have adapted it from user 'admin12'. For some reason I cannot post the link to the forum page. Hopefully someone can help me.

Code: Select all

on loginCheck
   -- use a global variable to hold the connection ID so other scripts can use it
    global gConnectionID
    
    -- set up the connection parameters - edit these to suit your database
    put "................." into tDatabaseAddress
    put "applogininfo" into tDatabaseName
    put "mydatabase" into tDatabaseUser
    put "password" into tDatabasePassword
    
    -- connect to the database
    put revOpenDatabase("MySQL", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
    
    -- check if it worked and display an error message if it didn't
    -- & set the connection ID global
    if tResult is a number then
        put tResult into gConnectionID
    else
        put empty into gConnectionID
        answer error "Unable to connect to the database:" & cr & tResult
    end if
   put "SELECT Username, Password FROM userpass" and put into theUN
   put revDataFromQuery(,,gConnectionID,theUN) into theUNData
      
   if theUNData = the text of field "username" and theUNData = the text of field "password" then
      go to card accessed
      else
         answer "Incorrect username or password. Please try again."
         exit to top
         end if
end loginCheck
Thanks
Jamie

Klaus
Posts: 11203
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Creating Login screen from SQL Problem

Post by Klaus » Thu Dec 24, 2015 8:17 pm

Hi Jamie,

what does "the result" tell you?

Not sure, but the dictionary reads "mysql" with NO capital letters, so please try:
...
put revOpenDatabase("mysql", tDatabaseAddress,...
...
And URLENCODE-ing the username and password is worth another try if it contains spaces and/or special (non ASCII) characters.


Best

Klaus

P.S.
You need to have at least 10 postings before you can post URLs and attachments.

Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: Creating Login screen from SQL Problem

Post by Jamie37 » Thu Dec 24, 2015 8:41 pm

Hello,

Thank you for your help. I have changed the capitals letters to lowercase but still no change. What did you mean by the second bit you said?

Thanks
Jamie

Klaus
Posts: 11203
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Creating Login screen from SQL Problem

Post by Klaus » Thu Dec 24, 2015 10:52 pm

Hi Jamie,

what is in -> tResult?
Maybe that will give a hint.

If our password and/or username contains spaces and/or special (non ASCII) characters you should:
---
put urlencode("what ever you have as password_##&&%%_1111") into tDatabasePassword
put urlencode(" a really lousy username") into tDatabaseUser
...
put revOpenDatabase("mysql", tDatabaseAddress, tDatabaseName, tDatabaseUser, tDatabasePassword) into tResult
...

And make sure your web provider actually allows direct remote connections to the MySQL database!
In most case this is forbidden and you have to use some "middleware" like PHP or Livecode Server.

And now do some christmas stuff, buddy! :D


Best

Klaus

Jamie37
Posts: 53
Joined: Sat Dec 19, 2015 1:45 pm

Re: Creating Login screen from SQL Problem

Post by Jamie37 » Fri Dec 25, 2015 6:16 pm

Hello Klaus,

Thank you for your help. It now works.

Thanks
Jamie

Klaus
Posts: 11203
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: Creating Login screen from SQL Problem

Post by Klaus » Fri Dec 25, 2015 6:27 pm

Great, what was it in the end?

Post Reply

Return to “Databases”