| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is an app for Nextcloud that offers user management and authentication with arbitrary SQL queries.
You can authenticate, create, delete users, change their password or display name, basically do (almost) everything that Nextcloud can do with users.
In contrast to the app SQL user backend, you write the SQL queries yourself. You are not limited by assumptions that app authors made about how your db is structured.
The app uses prepared statements and is written to be secure by default to prevent SQL injections. It understands the most popular standards for password hash formats: MD5-CRYPT, SHA256-CRYPT, SHA512-CRYPT, BCrypt, Argon2i and Argon2id. Because the various formats are recognized on-the-fly your db can can have differing hash string formats at the same time, which eases migration to newer formats.
This app primarily supports PostgreSQL and MariaDB/MySQL but the underlying PHP mechanism also supports Firebird, MS SQL, Oracle DB, ODBC, DB2, SQLite, Informix and IBM databases. By using an appropriate DSN you should be able to connect to these databases. This has not been tested, though.
See CHANGELOG.md for changes in newer versions. This app follows semantic versioning and there should not be any breaking changes unless the major version has changed.
You can find User Backend SQL Raw in the Security category of the Nextcloud app store inside your Nextcloud instance.
This app has no user interface. All configuration is done via Nextcloud's system configuration in config/config.php. This app uses the config key user_backend_sql_raw. The following code shows a complete configuration with all optional parameters commented out.
'user_backend_sql_raw' => array(
'dsn' => 'pgsql:host=/var/run/postgresql;dbname=theNameOfYourUserDb',
//'db_user' => 'yourDatabaseUser',
//'db_password' => 'thePasswordForTheDatabaseUser',
//'db_password_file' => '/path/to/file/ContainingThePasswordForTheDatabaseUser',
'queries' => array(
'get_password_hash_for_user' => 'SELECT password_hash FROM users_fqda WHERE fqda = :username',
'user_exists' => 'SELECT EXISTS(SELECT 1 FROM users_fqda WHERE fqda = :username)',
'get_users' => 'SELECT fqda FROM users_fqda WHERE (fqda ILIKE :search) OR (display_name ILIKE :search)',
//'set_password_hash_for_user' => 'UPDATE users SET password_hash = :new_password_hash WHERE local = split_part(:username, \'@\', 1) AND domain = split_part(:username, \'@\', 2)',
//'delete_user' => 'DELETE FROM users WHERE local = split_part(:username, \'@\', 1) AND domain = split_part(:username, \'@\', 2)',
//'get_display_name' => 'SELECT display_name FROM users WHERE local = split_part(:username, \'@\', 1) AND domain = split_part(:username, \'@\', 2)',
//'set_display_name' => 'UPDATE users SET display_name = :new_display_name WHERE local = split_part(:username, \'@\', 1) AND domain = split_part(:username, \'@\', 2)',
//'count_users' => 'SELECT COUNT (*) FROM users',
//'get_home' => '',
//'create_user' => 'INSERT INTO users (local, domain, password_hash) VALUES (split_part(:username, \'@\', 1), split_part(:username, \'@\', 2), :password_hash)',
),
//'hash_algorithm_for_new_passwords' => 'bcrypt',
),There are three types of configuration parameters:
that User Backend SQL Raw will connect to.
There are two methods to configure the database connection:
PostgreSQL works with method 1 and 2. MySQL works only with method 2. If you use db_password_file also set db_user (even for PostgreSQL) and don't put the username in the DSN. This is because, the underlying PDO classes have some quirks and diverge from the documented behaviour. So, better don't mix both methods. db_password_file has higher priority than db_password, but lower priority than password in DSN. But it's better to only set one source for the password, for the same reasons.
connect to PostgreSQL via a socket with ident authentication which requires no user or password at all:
'dsn' => 'pgsql:host=/var/run/postgresql;dbname=theNameOfYourUserDb',connect to PostgreSQL via TCP and user/password authentication:
'dsn' => 'pgsql:host=localhost;port=5432;dbname=theNameOfYourUserDb;user=theNameOfYourDbUser;password=thePasswordForTheDbUser',connect to PostgreSQL via TCP and user/password authentication and use password file:
'dsn' => 'pgsql:host=localhost;port=5432;dbname=theNameOfYourUserDb',
'db_user' => 'theNameOfYourDbUser',
'db_password_file' => '/path/to/password_file',connect to MySQL via socket which requires no user or password at all:
'dsn' => 'mysql:unix_socket=/var/run/mysql/mysql.sock;dbname=theNameOfYourUserDb',connect to MySQL via TCP and user/password authentication:
'dsn' => 'mysql:host=localhost;port=3306;dbname=testdb',
'db_user' => 'theNameOfYourDbUser',
'db_password' => 'thePasswordForTheDbUser', // or db_password_file insteadFor other databases check their PDO driver documentation pages which in-turn link to their respective DSN references. They either use method 1 or method 2 AFAICS.
that will be used to read/write data.
used for the creation of new passwords.
if not installed: apt install jq
watch logfile starting at the bottom:
jq -C 'select (.app=="user_backend_sql_raw")' /var/www/nextcloud/data/nextcloud.log | less -R +G| Back | FazBrowse Home | New Git URL |