mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-07-25 16:44:28 +00:00
Code fuer Accountgenerierung
This commit is contained in:
@@ -28,6 +28,7 @@ require_once('../../../include/benutzer.class.php');
|
||||
require_once('../../../addons/ldap/vilesci/ldap.class.php');
|
||||
require_once('../../../include/phrasen.class.php');
|
||||
require_once('../../../include/Crypt_CHAP-1.5.0/CHAP.php');
|
||||
require_once('../../../include/'.EXT_FKT_PATH.'/passwort.inc.php');
|
||||
|
||||
$uid = get_uid();
|
||||
$db = new basis_db();
|
||||
@@ -99,7 +100,7 @@ if(isset($_POST['change']))
|
||||
if($passwort_neu==$passwort_neu_check)
|
||||
{
|
||||
// Passwort Policy pruefen
|
||||
if(($errormsg = check_policy($passwort_neu))===true)
|
||||
if(($errormsg = check_policy($passwort_neu, $p))===true)
|
||||
{
|
||||
// Passwort aendern
|
||||
if(($msg = change_password($passwort_alt, $passwort_neu, $uid))===true)
|
||||
@@ -108,7 +109,7 @@ if(isset($_POST['change']))
|
||||
}
|
||||
else
|
||||
{
|
||||
echo '<span class="error">'.$msg.'</span>';
|
||||
echo '<span class="error">ERR:'.$msg.'</span>';
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -125,133 +126,4 @@ if(isset($_POST['change']))
|
||||
echo '</body>
|
||||
</html>';
|
||||
|
||||
/**
|
||||
* Prueft die Passwort Policy
|
||||
* @param $passwort_neu das neue Passwort
|
||||
* @return errormsg wenn Policy nicht erfuellt ist oder true wenn ok
|
||||
*/
|
||||
function check_policy($passwort_neu)
|
||||
{
|
||||
global $p;
|
||||
|
||||
// Prüfung des neuen Passwortes
|
||||
$errormsg='';
|
||||
$error=false;
|
||||
// Laenge mindestens 8 Zeichen
|
||||
if(mb_strlen($passwort_neu)<8)
|
||||
{
|
||||
$error=true;
|
||||
$errormsg .= $p->t('passwort/MinLaenge');
|
||||
}
|
||||
|
||||
// Mindestens 1 Großbuchstabe
|
||||
if(!preg_match('/[A-Z]/', $passwort_neu))
|
||||
{
|
||||
$error=true;
|
||||
$errormsg .=$p->t('passwort/Grossbuchstabe');
|
||||
}
|
||||
// Mindestens 1 Kleinbuchstabe
|
||||
if(!preg_match('/[a-z]/', $passwort_neu))
|
||||
{
|
||||
$error=true;
|
||||
$errormsg .=$p->t('passwort/Kleinbuchstabe');
|
||||
}
|
||||
|
||||
// Mindestens 1 Ziffer
|
||||
if(!preg_match('/[0-9]/', $passwort_neu))
|
||||
{
|
||||
$error=true;
|
||||
$errormsg .=$p->t('passwort/Ziffer');
|
||||
}
|
||||
|
||||
// Keine Leerzeichen
|
||||
if(strstr($passwort_neu, ' '))
|
||||
{
|
||||
$error=true;
|
||||
$errormsg .=$p->t('passwort/Leerzeichen');
|
||||
}
|
||||
|
||||
// keine Umlaute
|
||||
if(preg_match('/[ÄÖÜäöü]/', $passwort_neu))
|
||||
{
|
||||
$error=true;
|
||||
$errormsg .=$p->t('passwort/Umlaute');
|
||||
}
|
||||
|
||||
// Sonderzeichen
|
||||
if(!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z\-\$#\[\]\{\}!\(\)\.,\*:;_]{8,1024}$/', $passwort_neu))
|
||||
{
|
||||
$error=true;
|
||||
$errormsg.=$p->t('passwort/Sonderzeichen');
|
||||
}
|
||||
|
||||
if($error)
|
||||
return $errormsg;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Aendert das Passwort im LDAP
|
||||
* @param $passwort_alt Altes (aktuelles) Passwort
|
||||
* @param $passwort_neu neues Passwort
|
||||
* @param $uid UID
|
||||
* @return true wenn erfolgreich sonst false
|
||||
*/
|
||||
function change_password($passwort_alt, $passwort_neu, $uid)
|
||||
{
|
||||
$ldap = new ldap();
|
||||
|
||||
// Normalen Bind zum LDAP Server
|
||||
if($ldap->connect())
|
||||
{
|
||||
// DN des Users holen
|
||||
if($user_dn = $ldap->GetUserDN($uid))
|
||||
{
|
||||
$ldap->unbind();
|
||||
$ldap = new ldap();
|
||||
|
||||
// Bind des User mit alten Passwort
|
||||
if($ldap->connect(LDAP_SERVER_MASTER,LDAP_PORT,$user_dn, $passwort_alt, LDAP_STARTTLS))
|
||||
{
|
||||
// Passwort verschlüsseln
|
||||
//SSHA
|
||||
$salt = substr(pack('H*',hash('sha1',substr(pack('h*',hash('md5',mt_rand())),0,8).$passwort_neu)),0,4);
|
||||
$encrypted = base64_encode(pack('H*',hash('sha1',$passwort_neu.$salt)).$salt);
|
||||
$ssha_password = '{SSHA}'.$encrypted;
|
||||
|
||||
// LM und NT
|
||||
$hash = new Crypt_CHAP_MSv2();
|
||||
$hash->password = $passwort_neu;
|
||||
// $lm_password = strtoupper(bin2hex($hash->lmPasswordHash()));
|
||||
$nt_password = strtoupper(bin2hex($hash->ntPasswordHash()));
|
||||
|
||||
// Neues Passwort setzen
|
||||
$data = array();
|
||||
$data['userPassword']=$ssha_password;
|
||||
// $data['sambaLMPassword']=$lm_password;
|
||||
$data['sambaNTPassword']=$nt_password;
|
||||
$data['sambaPwdLastSet']=time();
|
||||
$data['sambaPwdMustChange']=2147483647; // 2038-01-19 04:14:07
|
||||
|
||||
if($ldap->Modify($user_dn, $data))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return $ldap->errormsg;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $ldap->errormsg;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return $ldap->errormsg;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user