Salve a tutti,
Ho creato questo piccolo codice per la creazione di un user in linux in fase di registrazione utente.
Codice PHP:
function Register($post, $process) {
if(isset($process)) {
$pass1 = $post['pass1'];
$pass2 = $post['pass2'];
$username = $post['username'];
$email_address = $post['email_address'];
$first_name = $post['first_name'];
$last_name = $post['last_name'];
$info = $post['info'];
$porta = $post['porta'];
$host = $post['host'];
if((!$pass1) || (!$pass2) || (!$username) || (!$email_address) || (!$first_name) || (!$last_name) || (!$info) || (!$porta) || (!$host)) {
return "Some Fields Are Missing";
}
if ($pass1 !== $pass2) {
return "Passwords do not match";
}
$query = $this->query("SELECT username FROM ".DBTBLE." WHERE username = '$username'");
if($query['num_rows'] > 0){
return "Username unavialable, please try a new username";
}
$query = $this->query("SELECT email_address FROM ".DBTBLE." WHERE email_address = '$email_address'");
if($query['num_rows'] > 0){
return "Emails address registered to another account.";
}
$comand = "/usr/sbin/useradd -m -p $pass1 $username";
$connection = ssh2_connect('IPSERVER', 22);
ssh2_auth_password($connection, 'USERROOT', 'PASSWORDROOT');
$stream = ssh2_exec($connection, $comand);
if (!$connection) die('Connection failed');
$this->query("INSERT INTO ".DBTBLE." (first_name, last_name, email_address, username, password, info, porta, host) VALUES ('$first_name', '$last_name', '$email_address', '$username', '".md5($pass1)."', '".htmlspecialchars($info)."', '$host', '$porta')");
return 'User was created.';
}
}
L'user viene creato con successo l'unico problema che la password non è corretta.Non so più cosa provare.
Grazie per l'aiuto che mi darete.