I can get list of usernames, unlock users, verify username/password, get days to expire for a password, but I cannot change the frigging password. Why not?
public function changePassword(string $username, string $current_password, string $password): bool
{
$result = false;
$connection = ldap_connect('ldaps://' . self::HOST . ':' . self::PORT);
if ($connection) {
ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
ldap_set_option(null, LDAP_OPT_DEBUG_LEVEL, 7);
if (#ldap_bind($connection, "uid=$username,ou=people,dc=bsg.na.baesystems,dc=com", $current_password)) {
//$userpassword = '{MD5}' . hash('md5', $password);
$userpassword = '{sha256}' . base64_encode(hash('sha256', $password, true));
//$userpassword = '{sha384}' . base64_encode(hash('sha384', $password, true));
$result = #ldap_mod_replace($connection, "uid=$username,ou=people,dc=bsg.na.baesystems.com,dc=com", [
'userpassword' => $userpassword
]);
}
}
if (!$result)
log_message('error', __METHOD__ . "\n" . ldap_error($connection));
return $result;
}
Related
<?php
const WEBHOOK_SECRET='secret key';
function verifySignature ($body, $signature) {
$digest = hash_hmac('sha1', $rawPost, WEBHOOK_SECRET);
return $signature !== $digest ;
}
if (!verifySignature(file_get_contents('php://input'), $_SERVER['HTTP_X_TAWK_SIGNATURE'])) {
// verification failed
}
// verification success
else{
$servername = "*******";
$username = "*******";
$password = "******";
$db = "*******";
$conn = new mysqli($servername, $username, $password, $db);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$json_string = file_get_contents('php://input');
$array_data = json_decode($json_string, true);
$sql = 'INSERT INTO twak (message) VALUES ("'.$array_data.'")';
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
?>
I am trying to store tawk to webhook response into my database but this code not giving webhook hook response . can anyone tell me what's the issue?
There is a mistake in the documentation, even it took me a while to find out why my script is not working. Inside function verifySignature, $rawPost should be $body
function verifySignature ($body, $signature) {
$digest = hash_hmac('sha1', $body, WEBHOOK_SECRET);
return $signature !== $digest ;
}
<?php
$domain = 'xxxx.com';
$username = 'xxxxxx';
$password = 'xxxxxx';
$ldapconfig['host'] = 'xxx.xxx.xxx.xxx';
$ldapconfig['port'] = 389;
$ldapconfig['basedn'] = 'dc=xxxx,dc=com';
$ds=ldap_connect($ldapconfig['host'], $ldapconfig['port']);
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ds, LDAP_OPT_REFERRALS, 0);
$dn="ou=Technology,".$ldapconfig['basedn'];
$bind=ldap_bind($ds, $username .'#' .$domain, $password);
$isITuser = ldap_search($bind,$dn,'(&(objectClass=User)(sAMAccountName=' . $username. '))');
if ($isITuser) {
echo("Login correct");
} else {
echo("Login incorrect");
}
?>
I am trying to connect to Active Directory servers. But, I get an error. "Login incorrect". Actually my purpose is to add user.
I've looked at a lot of other questions about this but can't seen to find the solution for my error.
The code I use is:
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
$ldapconn = ldap_connect('[HOST]', 389);
ldap_set_option($ldapconn, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldapconn, LDAP_OPT_REFERRALS, 0);
ldap_bind($ldapconn, $username, $password);
$authUser = $adldap->user()->authenticate($username, $password);
if ($authUser == true) {
echo "jep";
echo "<br />";
$basedn = "DC=lab,DC=kuhlmann-its,DC=local";
$classname = "TAI2";
$filter = "(memberOf=OU=" . $classname . ",OU=Accounts,OU=BBS_Students,OU=BBS,OU=EDUNET,DC=lab,DC=kuhlmann-its,DC=local)";
$attributes = array("cn");
$search = ldap_search($ldapconn, $basedn, $filter, $attributes);
$info = ldap_get_entries($ldapconn, $search);
This is my first time working with LDAP and Active Directory and I don't know how all the functions work. I want to know why my ldap_search() is not working.
Thanks in advance.
i've got an problem.
I try to connect to my MySQL-Database with this password:
Test12&#_#+.:-;}][{$%!/()?,*'"`<>
public function __construct() {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['dbName'])) {
$this->dbName = $_POST['dbName'];
}
if (isset($_POST['dbUser'])) {
$this->dbUser = $_POST['dbUser'];
}
if (isset($_POST['dbPass'])) {
$this->dbPass = $_POST['dbPass'];
}
}
}
public function connectToDatabase() {
try {
$dsn = 'mysql:dbname=' . $this->dbName . ';host=' . $this->dbHost . ';charset=utf8';
$options = array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
);
$dbh = new PDO($dsn, $this->dbUser, $this->dbPass, $options);
$this->isConnected = TRUE;
} catch (PDOException $e) {
echo $e->getMessage();
$this->isConnected = FALSE;
}
}
i always get the message:
SQLSTATE[HY000] [1045] Access denied for user 'web3_10'#'localhost' (using password: YES)
I think it's because of my overkill password.
How can i get this to work?
Next i have to import a Dump with this:
public function importDatabase($dbTarget) {
$stmt = 'mysql --host=' . $this->dbHost . ' --user=' . $this->dbUser . ' --password=' . $this->dbPass . ' ' . $this->dbName . ' ' . '<' . ' ' . $dbTarget;
var_dump($stmt);
exec($stmt, $output, $return);
if (!$return) {
$this->dbImported = TRUE;
}
}
same problem here. no import with this password.
How ca i fix this?
There could be a couple of problems here, so make sure:
You escaped your password string correctly (specifically characters like ' -> \')
Its actually the correct password (log in via console and see if it works)
Your user actually has the correct permissions for the tables.
Further, try to print your password string before connecting, and verify it is indeed correct.
I'm trying to connect to an LDAP server to authenticate user credentials.
I've found a few users with this same issue but their solutions did not work for me.
here's what I'm using:
<?php
define('LDAP_SERVER', 'LDAP://pdc.mydomain.com');
define('LDAP_PORT', 389);
define('LDAP_TOP', 'dc=mydomain,dc=com');
if(isset($_POST['username']))
{
if(!($ds = ldap_connect(LDAP_SERVER, LDAP_PORT)))
{
die ("Could not connect to mydomain domain");
}
$un = $_POST['username'].",".LDAP_TOP;
//echo stripslashes($un)."<br>";
$ldapbind = ldap_bind($ds, stripslashes($un), $_POST['password']);
if($ldapbind)
echo "login success";
else
echo "login failed";
}
?>
I've tried using "mydomain\myusername" and just "myusername".
I added the stripslashes() function when neither worked to test that, and still no dice.
the error I get every time is: Warning: ldap_bind(): Unable to bind to server: Invalid credentials
any help would be greatly appreciated
TIA
I know it is a pretty old question and if you still need an answer then what happens if you run this code in a single php file?
$username = 'hello';
$password = '123123';
$server = '192.168.32.4';
$domain = '#yourdomain.local';
$port = 389;
$connection = ldap_connect($server, $port);
if (!$connection) {
exit('Connection failed');
}
// Help talking to AD
ldap_set_option($connection , LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($connection , LDAP_OPT_REFERRALS, 0);
$bind = #ldap_bind($connection, $username.$domain, $password);
if (!$bind) {
exit('Binding failed');
}
// This is where you can do your work
echo 'Hello from LDAP';
ldap_close($connection );
More info is here.
Check whether your login and pass correct.
And before the login add domain. See in example bottom (HQ\login):
<?php
$login = 'HQ\student';
$password = 'MYPASS';
$ldap_link = ldap_connect('pdc.bc) or die("Could not connect to LDAP server.");
$ldapbind = #ldap_bind($ldap_link, $login, $password) or die ("Error trying to bind: ".ldap_error($ldap_link));
?>
I used these functions:
function authenticate($username, $password){
include 'conf/config.inc.php';
$ldap_Userdn = getUserDN($username);
if($ldap_Userdn!=""){
$ldap_con = ldap_connect($ldap_hostname,$ldap_port);
ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3);
if(ldap_bind($ldap_con, $ldap_Userdn, $password)){
return true;
} else {
//echo "<br>Error bind checkPassword function<br>";
return false;
}
} else {
echo "Error to find user DN" . ldap_error($ldap_con);
}
ldap_close($ldap_con);
}
function getUserDN($username){
include 'conf/config.inc.php';
$data = "";
$ldap_con = ldap_connect($ldap_hostname,$ldap_port);
ldap_set_option($ldap_con, LDAP_OPT_PROTOCOL_VERSION, 3);
ldap_set_option($ldap_con, LDAP_OPT_REFERRALS, 0);
if(ldap_bind($ldap_con, $ldap_dn, $ldap_password)){
$filter="(cn=$username)";
$dn=$ldap_search; //even if it seems obvious I note here that the dn is just an example, you'll have to provide an OU and DC of your own
$res = ldap_search($ldap_con, $ldap_search, $filter);
$first = ldap_first_entry($ldap_con, $res);
$data = ldap_get_dn($ldap_con, $first);
} else {
echo "<br>Error bind getUserDN function<br>" . ldap_error($ldap_con);
}
ldap_close($ldap_con);
return $data;
}
an this is my config.inc.php:
<?php
$ldap_hostname = "my openldap IP";
$ldap_port = "389";
$ldap_dn = "cn=Manager,dc=mydomain,dc=com";
$ldap_search = "dc=mydomain,dc=com";
$ldap_password ="my password";
?>