Another example of authenticating against a database [PHP]

Use this forum to share your network setup and what's been working for you.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
kimboslice
OpenVpn Newbie
Posts: 3
Joined: Tue Nov 01, 2022 3:57 pm

Another example of authenticating against a database [PHP]

Post by kimboslice » Mon Nov 28, 2022 9:32 am

Almost forgot to post this up, heres another example of authenticating against a database, this time in PHP with Bcrypt passwords

config:

Code: Select all

auth-user-pass-verify 'C:/PROGRA~1/PHP/v8.1.12/php.exe C:/path/to/Auth.php' via-file
Auth.php:

Code: Select all

<?php
if (!isset($argv[1]))
	{
	print 'not ok';
	exit(1);
	}
	
$data = file($argv[1], FILE_IGNORE_NEW_LINES);
// Add your [address], [dbuser], [pass], [database]
$conn = new mysqli("127.0.0.1", "root", "password", "openvpn");
if ($conn->connect_error) // maybe remove this when you have the script setup
{
    die("Connection failed: " . $conn->connect_error);
}
// Create  db named openvpn and a table named users
// Then add two columns, one named password and another named user
// populate them with [username], [bcrypt-hashed-pass]
$stmt = $conn->prepare("SELECT password FROM users WHERE user = ?");
$stmt->bind_param("s", $data[0]);
$stmt->execute();
$result = $stmt->get_result()->fetch_assoc();
if (!$result) { echo 'not ok'; exit(1); } // User non-existent
if (password_verify($data[1], $result['password']))
{
	echo 'ok';
	exit(0);
}
else
{
	echo 'not ok';
	exit(1);
}
?>

ramprasad.padala
OpenVpn Newbie
Posts: 1
Joined: Tue Dec 06, 2022 3:06 am

Re: Another example of authenticating against a database [PHP]

Post by ramprasad.padala » Tue Dec 06, 2022 3:07 am

Not a relevant post, sorry

Post Reply