User Login using sqlite

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

User Login using sqlite

Post by jwtea » Fri Mar 23, 2018 2:23 am

Hello, I'm just started using LiveCode few days ago and for today I'm stuck at making the user to login with the correct account details from the database. The database is created from sqlite by Livecode.

I got 2 fields , 1 for username and another 1 for password. I also got 1 button for user to log in.
name of username field= fieldforemail
name of password field = fieldforpw
name of button = loginbtn
name of table = account_details
table details = user_id integer primary key,email char(50), password char(50)


Basically i want the user to type in the correct username and password in the form then if the user type in the correct username and password which match the account_detail in the database then it allow them to go to the next page.

Can i know what code to be type in the button for the user to login???



PS: My database and table is created and work perfectly, As i'm able to insert and view the account_details data.

Below is my code for the card script.

---------------------------------------------------------------------------
## Use a script local variable to store the database id
local sDatabaseID

## Handlers to get and set the variable storing the database id
command setDatabaseID pDatabaseID
put pDatabaseID into sDatabaseID
end setDatabaseID

function getDatabaseID
return sDatabaseID
end getDatabaseID

command databaseConnect
local tDatabasePath, tDatabaseID
## The database must be in a writeable location
put specialFolderPath("documents") & "/runreaccount1.sqlite" into tDatabasePath

## Open a connection to the database
## If the database does not already exist it will be created
put revOpenDatabase("sqlite", tDatabasePath, , , , ) into tDatabaseID
## Store the database id as a custom property so other handlers can access it
setDatabaseID tDatabaseID
end databaseConnect

command databaseClose
revCloseDatbase sDatabaseID
end databaseClose
------------------------------------------------------------------------------------------------------

Any help is appreciated,thanks! :D

jexxo
Posts: 2
Joined: Thu Mar 22, 2018 3:40 pm

Re: User Login using sqlite

Post by jexxo » Fri Mar 23, 2018 10:33 am

What is the purpose and environment, where you want to run the LiveCode application?
A SQLite database, in it's "pure" form, isn't protected and easily readable by anyone. There is no authentication to access the database. This might be no issue for your application purpose, but it is always good to think twice about saving stuff which contains passwords, emails etc.

I wonder if the "Intermediate" section is for newbies like us.

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: User Login using sqlite

Post by jwtea » Fri Mar 23, 2018 11:07 am

Hello jexxo,
the SQLite database is source from a sqlite file in my desktop. I am storing fake details im only just playing around with livecode.

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

Re: User Login using sqlite

Post by Klaus » Fri Mar 23, 2018 12:02 pm

Hi jwtea,

I deleted your posting in the Beginners section.
I'm sure you will agree that one thread per problem is sufficient. 8)


Best

Klaus

MaxV
Posts: 1579
Joined: Tue May 28, 2013 2:20 pm
Location: Italy
Contact:

Re: User Login using sqlite

Post by MaxV » Fri Mar 23, 2018 3:57 pm

For example:
########CODE to copy and paste with your mouse#######
# I put all code in this example
on MouseUp
put revOpenDatabase("sqlite", specialFolderPath("documents") & "/runreaccount1.sqlite", , , , ) into tConnID
set the connID of this stack to tConnID # so we can retrieve it everywhere, and it's easier to debug
put the text of field "user" into tUser
put the text of field "password" into tPassword
put "SELECT password FROM users WHERE user='" & tUser & "'" into tSQL
put revDataFromQuery(tab,return,tconnID,tSQL) into tRecords
if tRecords = tPassword then
go to card 2
else
answer error "Bad password"
end if
end MouseUp
########END OF CODE generated by this livecode app: http://tinyurl.com/j8xf3xq ########
########Code tested with livecode 9.0.0-rc-1########
Livecode Wiki: http://livecode.wikia.com
My blog: https://livecode-blogger.blogspot.com
To post code use this: http://tinyurl.com/ogp6d5w

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: User Login using sqlite

Post by FourthWorld » Fri Mar 23, 2018 6:43 pm

jwtea, help me understand so we can provide the best assistance: if this is for a single user on a local system what is the password used for? Once we understand the goal you're aiming for we'll be well suited to point you on the path to achieving that.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: User Login using sqlite

Post by jwtea » Sat Mar 24, 2018 4:20 pm

Hello MaxV,
I have try put your code into my button script and it worked perfectly!!!
Thank you very much and really appreciate your help! :D :D

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: User Login using sqlite

Post by jwtea » Sat Mar 24, 2018 4:22 pm

Hello FourthWorld,
I have created a interface to create user and im trying a interface to allow the user i created to log in that all!
I'm only playing around with livecode as im still quite new in this software!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: User Login using sqlite

Post by FourthWorld » Sat Mar 24, 2018 5:09 pm

jwtea wrote:
Sat Mar 24, 2018 4:22 pm
Hello FourthWorld,
I have created a interface to create user and im trying a interface to allow the user i created to log in that all!
I'm only playing around with livecode as im still quite new in this software!
I understand what you're doing. I was asking about why you're doing it, so we can provide guidance to help.

SQLite is not multi-user, and a desktop machine has only one user logged in at a time. Most uses of SQLite do not involve user accounts, which is why I was hoping to get a better understanding of how you envision the app's workflow to play out among multiple users.

On separate note, passwords aren't normally stored in a DB. Only a one-way hash is stored, ideally salted. Using LC's UUID or randomBytes (converted to hex) will provide a suitable salt, stored in a field with the user record. The password is commonly double-hashed to slow down cracking, once alone and that value hashed with the salt. The return value can be converted from its native binary form to hex with the binaryEncode function. For the hashing itself, use the messageDigest function in v9, with "sha-2" or "sha-3"; the sha1Digest function in older versions is too weak to rely on for password hashing, and md5Digest even weaker.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Talking LiveCode”