Skip to content

Commit 0866297

Browse files
committed
Add inital documentation
References: #581
1 parent 5d4828a commit 0866297

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed

README.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Supported Golang version:
3333
- [Mac OSX](#mac-osx)
3434
- [Windows](#windows)
3535
- [Errors](#errors)
36+
- [User Authentication](#user-authentication)
37+
- [Compile](#compile)
38+
- [Usage](#usage)
39+
-
3640
- [Extensions](#extensions)
3741
- [Spatialite](#spatialite)
3842
- [FAQ](#faq)
@@ -76,6 +80,9 @@ Boolean values can be one of:
7680

7781
| Name | Key | Value(s) | Description |
7882
|------|-----|----------|-------------|
83+
| UA - Create | `_auth` | - | Create User Authentication, for more information see [User Authentication](#user-authentication) |
84+
| UA - Username | `_auth_user` | - | Username for User Authentication, for more information see [User Authentication](#user-authentication) |
85+
| UA - Password | `_auth_pass` | - | Password for User Authentication, for more information see [User Authentication](#user-authentication) |
7986
| Auto Vacuum | `_auto_vacuum` \| `_vacuum` | <ul><li>`0` \| `none`</li><li>`1` \| `full`</li><li>`2` \| `incremental`</li></ul> | For more information see [PRAGMA auto_vacuum](https://www.sqlite.org/pragma.html#pragma_auto_vacuum) |
8087
| Busy Timeout | `_busy_timeout` \| `_timeout` | `int` | Specify value for sqlite3_busy_timeout. For more information see [PRAGMA busy_timeout](https://www.sqlite.org/pragma.html#pragma_busy_timeout) |
8188
| Case Sensitive LIKE | `_case_sensitive_like` \| `_cslike` | `boolean` | For more information see [PRAGMA case_sensitive_like](https://www.sqlite.org/pragma.html#pragma_case_sensitive_like) |
@@ -144,6 +151,7 @@ go build --tags "icu json1 fts5 secure_delete"
144151
| Secure Delete | sqlite_secure_delete | This compile-time option changes the default setting of the secure_delete pragma.<br><br>When this option is not used, secure_delete defaults to off. When this option is present, secure_delete defaults to on.<br><br>The secure_delete setting causes deleted content to be overwritten with zeros. There is a small performance penalty since additional I/O must occur.<br><br>On the other hand, secure_delete can prevent fragments of sensitive information from lingering in unused parts of the database file after it has been deleted. See the documentation on the secure_delete pragma for additional information |
145152
| Secure Delete (FAST) | sqlite_secure_delete_fast | For more information see [PRAGMA secure_delete](https://www.sqlite.org/pragma.html#pragma_secure_delete) |
146153
| Tracing / Debug | sqlite_trace | Activate trace functions |
154+
| User Authentication | sqlite_userauth | SQLite User Authentication see [User Authentication](#user-authentication) for more information. |
147155

148156
# Compilation
149157

@@ -303,6 +311,93 @@ For example the TDM-GCC Toolchain can be found [here](ttps://sourceforge.net/pro
303311
go install github.com/mattn/go-sqlite3
304312
```
305313
314+
# User Authentication
315+
316+
This package supports the SQLite User Authentication module.
317+
318+
## Compile
319+
320+
To use the User authentication module the package has to be compiled with the tag `sqlite_userauth`. See [Features](#features).
321+
322+
## Usage
323+
324+
### Create protected database
325+
326+
To create a database protected by user authentication provide the following argument to the connection string `_auth`.
327+
This will enable user authentication within the database. This option however requires two additional arguments:
328+
329+
- `_auth_user`
330+
- `_auth_pass`
331+
332+
When `_auth` is present on the connection string user authentication will be enabled and the provided user will be created
333+
as an `admin` user. After initial creation, the parameter `_auth` has no effect anymore and can be omitted from the connection string.
334+
335+
Example connection string:
336+
337+
Create an user authentication database with user `admin` and password `admin`.
338+
339+
`file:test.s3db?_auth&_auth_user=admin&_auth_pass=admin`
340+
341+
### Restrictions
342+
343+
Operations on the database regarding to user management can only be preformed by an administrator user.
344+
345+
### Support
346+
347+
The user authentication supports two kinds of users
348+
349+
- administrators
350+
- regular users
351+
352+
### User Management
353+
354+
User management can be done by directly using the `*SQLiteConn` or by SQL.
355+
356+
#### SQL
357+
358+
The following sql functions are available for user management.
359+
360+
| Function | Arguments | Description |
361+
|----------|-----------|-------------|
362+
| `authenticate` | username `string`, password `string` | Will authenticate an user, this is done by the connection; and should not be used manually. |
363+
| `auth_user_add` | username `string`, password `string`, admin `int` | This function will add an user to the database.<br>if the database is not protected by user authentication it will enable it. Argument `admin` is an integer identifying if the added user should be an administrator. Only Administrators can add administrators. |
364+
| `auth_user_change` | username `string`, password `string`, admin `int` | Function to modify an user. Users can change their own password, but only an administrator can change the administrator flag. |
365+
| `authUserDelete` | username `string` | Delete an user from the database. Can only be used by an administrator. The current logged in administrator cannot be deleted. This is to make sure their is always an administrator remaining. |
366+
367+
These functions will return an integer.
368+
369+
- 0 (SQLITE_OK)
370+
- 23 (SQLITE_AUTH) Failed to perform due to authentication or insufficient privileges
371+
372+
##### Examples
373+
374+
```sql
375+
// Autheticate user
376+
// Create Admin User
377+
SELECT auth_user_add('admin2', 'admin2', 1);
378+
379+
// Change password for user
380+
SELECT auth_user_change('user', 'userpassword', 0);
381+
382+
// Delete user
383+
SELECT user_delete('user');
384+
```
385+
386+
#### *SQLiteConn
387+
388+
The following functions are available for User authentication from the `*SQLiteConn`.
389+
390+
| Function | Description |
391+
|----------|-------------|
392+
| `Authenticate(username, password string) error` | Authenticate user |
393+
| `AuthUserAdd(username, password string, admin bool) error` | Add user |
394+
| `AuthUserChange(username, password string, admin bool) error` | Modify user |
395+
| `AuthUserDelete(username string) error` | Delete user |
396+
397+
### Attached database
398+
399+
When using attached databases. SQLite will use the authentication from the `main` database for the attached database(s).
400+
306401
# Extensions
307402
308403
If you want your own extension to be listed here or you want to add a reference to an extension; please submit an Issue for this.

0 commit comments

Comments
 (0)