-
Notifications
You must be signed in to change notification settings - Fork 53
USERS Module
sudo yum install mysql
sudo yum install mysql-devel
In case of trouble see MySQL documentation.
Get the installation package here. You can ignore v8 ads, as v5.7 already had everything that was ever needed for this kind of project and works seamlessly with old plain, fast and straightforward C connector. The last version was 5.7.26. Choose Custom installation and tick only MySQL server and Connector/C 6.1. Unless of course, you know what you're doing and want some additives.
Let's suppose we want to create a database for Toy Facebook.
-
You need to have the path to MySQL
bin
directory added to your environment. In the command line you need to be able to invokemysql
command. -
Log in to mysql command line tool:
mysql -u root --password=mysqlrootpassword
- Create user:
create user 'silgy'@'localhost' identified by 'silgypassword';
grant all privileges on * . * to 'silgy'@'localhost';
quit
- Go to mysql again, as silgy user:
mysql -u silgy --password=silgypassword
- Create database:
create database tfb;
quit
- Create tables. Use this SQL script.
cd tfb/lib
mysql -u silgy --password=silgypassword tfb < users.sql
Both DBMYSQL and USERS must be defined:
#define DBMYSQL
#define USERS
Add MySQL library path and name, so your m script would look like this:
#!/bin/sh
echo Making silgy_app...
g++ silgy_app.cpp \
../lib/silgy_eng.c ../lib/silgy_lib.c ../lib/silgy_usr.c \
-I. -I../lib \
-I/usr/include/mysql55 \
-L/usr/lib64/mysql -lmysqlclient \
-lrt -lz \
-s -O3 \
-o ../bin/silgy_app
At least this script works on AWS AMI distro, you may need to verify your paths if using something else.
Add database connection details to $SILGYDIR/bin/silgy.conf
:
dbName=tfb
dbUser=silgy
dbPassword=silgypassword
You can download Toy Facebook project as a template for a typical web application with users.
You may want to learn about sessions in Silgy first.
By default, users are authenticated by login. login form field can contain login or email and silgy_usr_login() will try both. Alternatively, you can use USERSBYEMAIL switch to use exclusively email.
Successful silgy_usr_login() call does the following:
- Sets the uses array record values (accessible via US macro),
- Adds record to users_logins table,
- Adds ls cookie to the response,
- Updates
users.visits
andusers.last_login
.
Adding keep=on to the login request will set ls cookie expiration time to now + USER_KEEP_LOGGED_DAYS days. Therefore – until you call silgy_usr_logout() – every subsequent request with valid ls cookie and the same User Agent as in the initial request, will automatically mark session as logged in.
Without keep=on cookie does not have expiration time, so by default it will expire by the end of the current browser session.
Logged in sessions are cached for LUSES_TIMEOUT seconds after last activity.
Unsuccessful login count and time is stored in users.ula_cnt
and users.ula_time
. Then there are 4 tresholds affecting the next attempts:
Macro | Description | Default |
---|---|---|
MAX_ULA_BEFORE_FIRST_SLOW | Maximum unsuccessful login attempts before first slowing down (1 attempt per minute will be allowed) | 10 |
MAX_ULA_BEFORE_SECOND_SLOW | Maximum unsuccessful login attempts before second slowing down (1 attempt per hour will be allowed) | 25 |
MAX_ULA_BEFORE_THIRD_SLOW | Maximum unsuccessful login attempts before third slowing down (1 attempt per 23 hours will be allowed) | 100 |
MAX_ULA_BEFORE_LOCK | Maximum unsuccessful login attempts before locking user out | 1000 |