Login
#31
To get the values out, you just use a SELECT sql command:
Code:
SELECT * FROM password WHERE name='Niels';

Then, there's the Lua binding, which dictates how to get to the values that the SQL database returns. It turns out the binding is pretty straightforward. You call the "exec" function on the database object, it has three parameters, the sql command, callback and userdata. It then calls the callback for each row of data that the sql command produced. The userdata parameter is given to the callback as well, it is a way to pass any kind of information through. So, for example, this will be a skeleton code for you:
-- Somewhere global:
PwdDB = {};  -- The password database object

-- In the Initialize function:
PwdDB, ErrCode, ErrMsg = sqlite3.open("pwd.sqlite");
-- TODO: Handle errors in ErrCode

-- In the login hook:
local UserName = ...;  -- Username of the player logging in
local PasswordGiven = ...;  -- What password is the user logging in with?
local ShouldAllowLogin = false;
local function ProcessRow(UserData, NumCols, Values, Names)
	for i = 1, NumCols do
		if (Names[i] == "Password") then  -- "Password" is the column name
			ShouldAllowLogin = (Values[i] == PasswordGiven);
		end
	end
	return 0;
end
local Res = PwdDB:exec("SELECT * FROM Passwords WHERE Username=\"" .. UserName .."\"", ProcessRow, nil);
if (Res ~= sqlite3.OK) then
	LOG("SQL query failed: " .. Res .. " (" .. PwdDB:errmsg() .. ")");
end;
-- ShouldAllowLogin now has the bool value saying whether to allow the user in or not
Reply
Thanks given by: NiLSPACE


Messages In This Thread
Login - by NiLSPACE - 02-22-2013, 01:30 AM
RE: Login - by xoft - 02-22-2013, 01:55 AM
RE: Login - by NiLSPACE - 02-22-2013, 01:58 AM
RE: Login - by bearbin - 02-22-2013, 05:50 AM
RE: Login - by NiLSPACE - 02-22-2013, 05:57 AM
RE: Login - by bearbin - 02-23-2013, 09:40 PM
RE: Login - by NiLSPACE - 02-23-2013, 09:53 PM
RE: Login - by bearbin - 02-23-2013, 10:00 PM
RE: Login - by NiLSPACE - 02-23-2013, 10:14 PM
RE: Login - by bearbin - 02-23-2013, 10:15 PM
RE: Login - by NiLSPACE - 02-23-2013, 10:53 PM
RE: Login - by bearbin - 02-23-2013, 11:09 PM
RE: Login - by NiLSPACE - 02-23-2013, 11:10 PM
RE: Login - by bearbin - 02-23-2013, 11:19 PM
RE: Login - by NiLSPACE - 02-23-2013, 11:21 PM
RE: Login - by bearbin - 02-23-2013, 11:26 PM
RE: Login - by NiLSPACE - 02-23-2013, 11:28 PM
RE: Login - by bearbin - 02-23-2013, 11:46 PM
RE: Login - by NiLSPACE - 02-23-2013, 11:47 PM
RE: Login - by NiLSPACE - 03-07-2013, 01:57 AM
RE: Login - by NiLSPACE - 03-07-2013, 04:12 AM
RE: Login - by NiLSPACE - 03-18-2013, 02:31 AM
RE: Login - by NiLSPACE - 03-24-2013, 12:00 AM
RE: Login - by NiLSPACE - 03-25-2013, 04:18 AM
RE: Login - by NiLSPACE - 03-30-2013, 09:09 PM
RE: Login - by NiLSPACE - 06-01-2013, 05:43 AM
RE: Login - by xoft - 06-01-2013, 05:57 AM
RE: Login - by NiLSPACE - 06-01-2013, 05:58 AM
RE: Login - by xoft - 06-01-2013, 06:43 AM
RE: Login - by NiLSPACE - 06-01-2013, 07:32 AM
RE: Login - by xoft - 06-01-2013, 05:41 PM
RE: Login - by NiLSPACE - 06-01-2013, 09:06 PM
RE: Login - by NiLSPACE - 06-01-2013, 10:31 PM
RE: Login - by bearbin - 06-02-2013, 12:45 AM
RE: Login - by testeflighter - 06-11-2013, 09:20 PM
RE: Login - by NiLSPACE - 06-12-2013, 12:46 AM
RE: Login - by testeflighter - 06-12-2013, 01:02 AM
RE: Login - by xoft - 06-12-2013, 01:06 AM
RE: Login - by testeflighter - 06-12-2013, 01:34 AM
RE: Login - by NiLSPACE - 06-12-2013, 01:38 AM
RE: Login - by tonibm19 - 10-06-2013, 09:08 PM
RE: Login - by NiLSPACE - 10-06-2013, 09:18 PM
RE: Login - by tonibm19 - 10-06-2013, 09:24 PM
RE: Login - by NiLSPACE - 10-20-2013, 12:57 AM
RE: Login - by xoft - 10-20-2013, 06:19 AM
RE: Login - by NiLSPACE - 10-20-2013, 06:26 AM
RE: Login - by tigerw - 10-20-2013, 10:08 PM
RE: Login - by Pentium44 - 12-15-2014, 02:12 PM
RE: Login - by Pentium44 - 12-15-2014, 02:32 PM
RE: Login - by job_123 - 01-03-2015, 04:39 AM
RE: Login - by jan64 - 01-05-2015, 09:58 PM
RE: Login - by yanderu2 - 02-11-2015, 02:00 AM
RE: Login - by jan64 - 02-14-2015, 06:19 AM
RE: Login - by yanderu2 - 02-14-2015, 09:25 PM
RE: Login - by jan64 - 02-14-2015, 09:52 PM
RE: Login - by xoft - 02-14-2015, 09:57 PM
RE: Login - by yanderu2 - 02-15-2015, 09:10 PM
RE: Login - by NiLSPACE - 02-15-2015, 09:38 PM
RE: Login - by jan64 - 02-15-2015, 09:52 PM
RE: Login - by NiLSPACE - 02-16-2015, 09:11 PM
RE: Login - by NiLSPACE - 02-21-2015, 08:39 AM
RE: Login - by jan64 - 02-22-2015, 12:12 AM
RE: Login - by NiLSPACE - 02-22-2015, 12:19 AM
RE: Login - by NiLSPACE - 02-22-2015, 08:41 AM
RE: Login - by jan64 - 02-22-2015, 08:24 PM
RE: Login - by NiLSPACE - 02-22-2015, 08:36 PM
RE: Login - by jan64 - 02-22-2015, 08:43 PM
RE: Login - by NiLSPACE - 03-01-2015, 06:17 AM
RE: Login - by NiLSPACE - 03-03-2015, 02:30 AM
RE: Login - by jan64 - 03-03-2015, 03:10 AM
RE: Login - by xoft - 03-03-2015, 04:06 AM
RE: Login - by NiLSPACE - 04-03-2015, 09:04 PM
RE: Login - by NiLSPACE - 04-05-2015, 12:02 AM
RE: Login - by Serial - 05-23-2015, 08:44 AM
RE: Login - by NiLSPACE - 05-23-2015, 08:51 AM
RE: Login - by Serial - 05-23-2015, 11:44 AM
RE: Login - by NiLSPACE - 12-30-2015, 02:03 AM
RE: Login - by NiLSPACE - 01-28-2016, 05:24 AM
RE: Login - by KoukiShichirou - 05-25-2016, 05:39 AM
RE: Login - by NiLSPACE - 07-19-2016, 10:17 PM
RE: Login - by Boo - 09-03-2016, 09:32 PM
RE: Login - by NiLSPACE - 09-03-2016, 10:28 PM
RE: Login - by Boo - 09-05-2016, 02:20 AM
RE: Login - by NiLSPACE - 09-05-2016, 02:25 AM
RE: Login - by Boo - 09-05-2016, 02:31 AM
RE: Login - by NiLSPACE - 09-05-2016, 02:33 AM
RE: Login - by Boo - 09-05-2016, 02:50 AM
RE: Login - by NiLSPACE - 09-05-2016, 03:25 AM
RE: Login - by DrMasik - 09-05-2016, 03:57 AM
RE: Login - by NiLSPACE - 09-05-2016, 04:14 AM
RE: Login - by NiLSPACE - 09-05-2016, 05:12 AM
RE: Login - by yangm97 - 11-27-2016, 01:37 PM
RE: Login - by NiLSPACE - 11-27-2016, 04:37 PM
RE: Login - by ShadowCone - 11-27-2016, 06:56 PM
RE: Login - by NiLSPACE - 11-27-2016, 08:50 PM
RE: Login - by yangm97 - 11-28-2016, 12:58 AM
RE: Login - by NiLSPACE - 11-28-2016, 01:12 AM
RE: Login - by yangm97 - 11-28-2016, 01:52 AM
RE: Login - by NiLSPACE - 11-28-2016, 01:56 AM
RE: Login - by yangm97 - 11-28-2016, 03:37 AM
RE: Login - by deepdream - 02-16-2021, 11:41 AM
RE: Login - by NiLSPACE - 02-18-2021, 07:31 PM
RE: Login - by deepdream - 02-21-2021, 07:59 PM
RE: Login - by NiLSPACE - 02-25-2021, 08:28 PM
RE: Login - by Jmaniacs - 06-02-2021, 04:14 AM
RE: Login - by Jmaniacs - 06-02-2021, 04:20 AM
RE: Login - by NiLSPACE - 06-02-2021, 04:35 AM



Users browsing this thread: 3 Guest(s)