< Logiciel Pastèque < API
DB setup
[as postgres] create user U with password 'Y'; create database X with owner = U template = template0; grant all privileges on database X to U; [as pasteque user] \i res/database/postgresql/schema.sql
Configuration postgresql for dummies
edit /etc/postgresql/X.Y/main/pg_hba.conf
local all all peer
becomes
local all postgres peer\\ local all all md5
For crontask of pgdump:
edit /root/.pgpass (root:root 600)
localhost:5432:<user>:<db>:<password>
Escape any : char with \:
Account creation
Use this snippet to generate passwords
<html dir="ltr" lang="en-US"> <head> <meta charset="UTF-8" /> <title>password_hash</title> <style type="text/css"> pre { border: 1px solid #444; padding: 1ex; } </style> </head> <body> <h1>Password hash generator</h1> <form action="user_ini.php" method="POST" onsubmit="javascript:sendpwd();"> <p>Enter password here</p> <p><input type="password" name="password" placeholder="password to hash" /></p> <p><input type="submit" value="send" /></p> </form> <h2>Your <user>_id.ini file</h2> <pre><?php if (array_key_exists('password', $_POST)) { echo htmlspecialchars("password=" . password_hash($_POST['password'], PASSWORD_DEFAULT)); } else { echo "Empty, use the form above"; }?></pre> <h2>Server source code</h2> <p>This is the php code running this page and filling the <user>_id.ini block.</p> <pre>if (array_key_exists('password', $_POST)) { echo htmlspecialchars("password=" . password_hash($_POST['password'], PASSWORD_DEFAULT)); } else { echo "Empty, use the form above"; }</pre> <h2>Standalone script</h2> <p>Call with php-cli, enter the password twice, outputs the hash. Usage:</p> <pre>php hasher.php > login_id.ini</pre> <pre><?php if ($argc < 2) { system("stty -echo"); $password = substr(fread(STDIN, 80), 0, -1); $password2 = substr(fread(STDIN, 80), 0, -1); system("stty echo"); if ($password != $password2) { file_put_contents("php://stderr", "Password mismatch\n"); die(); } } else { $password = $argv[1]; } echo "password=" . password_hash($password, PASSWORD_DEFAULT);</pre> <body> </html>
Put the output into auth/<ident>_id.ini
and create an auth/<ident>_db.ini
file following this scheme
type = postgresql host = localhost port = 5432 name = "pg_user" user = "pg_db" password = "pg_pwd"
Obviously, you need to change name
, user
and password
parameters. You can either use mysql
but it's not recommanded (in this case, obviously you need to change port
to 3306)
Cet article est issu de Wikibooks. Le texte est sous licence Creative Commons - Attribution - Partage dans les Mêmes. Des conditions supplémentaires peuvent s'appliquer aux fichiers multimédias.