[英]Creating a PHP script that will check for username and password combo in LDAP
我正在嘗試創建一個 php 腳本,用於檢查我的 ldap 目錄中是否存在用戶名和密碼組合。 我會發布到目前為止我所擁有的。
<?php
$username = $_POST["username"];
$password = $_POST["password"];
$ldapconn = ldap_connect("localhost")
or die("Could not connect to LDAP server.");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldaprdn = "cn=$username,dc=designstudio1,dc=com";
$ldappass = "$password";
if ($ldapconn) {
$ldapbind = ldap_bind($ldapconn, $ldarprdn, $ldarppass);
if ($ldapbind) {
echo "Welcome back, $username!";
} else {
echo "Authentication failed. Please check your username/password and try again.";
}
}
?>
如果你需要它,這是我的 php 表格。
<!DOCTYPE html>
<html lang="en">
<html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form id="contact-form" action="script.php" method="post">
<input type="hidden" name="redirect" />
<ul>
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" />
<label for="password">Password:</label>
<input type="password" name="password" id="password" value="" />
<input type="submit" value="submit" />
</ul>
</form>
</body>
</html>
我輸入的每個用戶名和密碼(有效與否),它總是向我顯示歡迎信息。
由於我的代碼清楚地顯示了這一點,因此我對 php 和 ldap 仍然很陌生。 任何幫助,將不勝感激。
我也會編輯我的代碼,因為我會提出建議的更改以及我發現不適合的任何內容。
正如其他用戶(評論中的@Sammitch)所指出的那樣,php 變量中幾乎沒有拼寫錯誤。
試試下面的代碼,我發現並修復了變量中的拼寫錯誤,沒有別的,除了這段代碼看起來不錯。
還要考慮@Sammitch 建議啟用錯誤報告
<?php
$username = $_POST["username"];
$password = $_POST["password"];
$ldapconn = ldap_connect("localhost")
or die("Could not connect to LDAP server.");
ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldaprdn = "cn=$username,dc=designstudio1,dc=com";
$ldappass = "$password";
if ($ldapconn) {
//Below line had several spelling mistakes
$ldapbind = ldap_bind($ldapconn, $ldaprdn, $ldappass);
if ($ldapbind) {
echo "Welcome back, $username!";
} else {
echo "Authentication failed. Please check your username/password and try again.";
}
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.