i try to add a user to freeipa with the code below. the code return success but when i go to the freeipa UI the user is not visible. if i try to reinsert it will fail telling that user already exist. what can be? thanks
$con = ldap_connect($server);
ldap_set_option($con, LDAP_OPT_PROTOCOL_VERSION, 3);
// bind anon and find user by uid
$user_search = ldap_search($con,$dn,"(|(uid=admin))");
$user_get = ldap_get_entries($con, $user_search);
$user_entry = ldap_first_entry($con, $user_search);
$user_next = ldap_next_entry($con, $user_entry);
$user_dn = ldap_get_dn($con, $user_next);
if (ldap_bind($con, $user_dn, "adminpass") === false) {
$message[] = "Error E101 - Current Username or Password is wrong.";
}else{
$info['givenName'] = "test";
$info['cn'] = "test";
$info['sn'] = "user";
$info['mail'] = "test#localhost";
$info['objectclass'][0] = "inetorgperson";
if(ldap_add($con, "cn=test,cn=users,cn=accounts,dc=domain,dc=net", $info) === false){
$error = ldap_error($con);
$errno = ldap_errno($con);
$message[] = "$errno - $error";
}else{
$message[] = "ok";
}
}
Related
When creating the user I cannot start the section with the user's password. The user is created, but when testing the connection, it marks invalid credentials. Can you tell me where I am wrong? How should the password be encrypted?
$ds = '192.168.1.10';
$portldap = 389;
$ldap_username = 'CN=Administrador,CN=Users,DC=Local,DC=com';
$ldap_password = 'rootadm1';
$ldap_password_user = $ldap_password;
$ldap_connection = ldap_connect($ds, $portldap);
if($ldap_connection ){
// We have to set this option for the version of Active Directory we are using.
ldap_set_option($ldap_connection, LDAP_OPT_PROTOCOL_VERSION, 3) or die('Unable to set LDAP protocol version');
ldap_set_option($ldap_connection, LDAP_OPT_REFERRALS, 0); // We need this for doing an LDAP search.
$r = ldap_bind($ldap_connection, $ldap_username, $ldap_password);
if($r === TRUE){
$CN = htmlspecialchars($_POST["cn"]);
$ldaprecord['cn'] = $CN;
$ldaprecord['sAMAccountName'] = $_POST["sAMAccountName"]; //20caract
$ldaprecord['userPrincipalName'] = $_POST["userprincipalname"];
$ldaprecord["objectClass"][0] = "top";
$ldaprecord["objectClass"][1] = "person";
$ldaprecord["objectClass"][2] = "organizationalPerson";
$ldaprecord["objectClass"][3] = "user";
$ldaprecord['description']= $_POST["description"];
$ldaprecord["userAccountControl"][0] = "66656";
$ldap_new = 'CN='.$CN.',CN=Users,DC=Local,DC=com';
$result = ldap_add($ldap_connection, $ldap_new, $ldaprecord);
if($result) {
//Success creating user - Add password
$addPrecord['userPassword'] = '{MD5}' . base64_encode(pack('H*',md5($ldap_password_user)));
//$addPrecord["unicodePwd"][0] = iconv( 'UTF-8', 'UTF-16LE', $ldap_password_user );
$add_record= ldap_modify($ldap_connection, $ldap_new, $addPrecord);
if($add_record){
ldap_close($ldap_connection);
return $result;
}
else {
echo "LDAP Error: ".ldap_error($ldap_connection)."\n";
exit;
}
}
else {
echo "LDAP Error: ".ldap_error($ldap_connection)."\n";
exit;
}
}
}
else {
echo "cannot connect to LDAP server at $ds.";
} ```
[enter image description here][1]
[1]: https://i.stack.imgur.com/QOzqZ.png
i have code like this
<?php
require('../config.php');
require_once($CFG->dirroot . '/user/editlib.php');
$errorMessage = '';
$successMessage = '';
if(isset($_SESSION['successMessage']))
{
$successMessage = $_SESSION['successMessage'];
unset($_SESSION['successMessage']);
}
if (isset($_POST['register'])) {
if(!preg_match("/^(?=.*[0-9])(?=.*[a-z])(\S+)$/i", $_POST['password']))
{
$errorMessage="don't allow spaces";
}
$errors = array();
$data = array();
$chk_sql = "SELECT * FROM {user} u where username = ?";
if (!empty($chk_sql) ) {
$errorMessage='Username already taken';
}
if(!$chk_username = $DB->get_record_sql($chk_sql, array($_POST['username'])) )
{
$secret = $_POST['secret'];
$access_code_sql = "SELECT * FROM {accesscode} WHERE random_no= ? and status=1";
if($chk_secret = $DB->get_record_sql($access_code_sql, array($secret)) )
{
if ( $chk_secret->used >= $chk_secret->number ) {
$errorMessage = "your access code limit completed..";
}
else
{
$cadminid = $chk_secret->cadmin_id;
$clientid = $chk_secret->clientid;
$DB->execute("UPDATE {accesscode} SET used = used+1 WHERE random_no = '$secret'");
$insert_record = new stdClass();
$insert_record->firstname = $_POST['firstname'];
$insert_record->lastname = $_POST['lastname'];
$insert_record->username = $_POST['username'];
$insert_record->secret = $secret;
$insert_record->password = password_hash($_POST['password'], PASSWORD_DEFAULT);
$insert_record->timecreated = time();
$insert_record->maildigest = $cadminid;
$insert_record->maildisplay = $clientid;
$insert_record->idnumber = 1;
$insert_record->mnethostid = 1;
$insert_record->confirmed = 1;
$insert_record->email = $_POST['email'];
if($result = $DB->insert_record('user', $insert_record))
{
$_SESSION['successMessage'] = "record created successfully";
header('Location: register.php');
}
else
$errorMessage = "error! can you please try again";
}
}
else
$errorMessage = "your access code is wrong..";
}
}
?>
so i want to write condition like another if condition
if ( $chk_secret->status='0' ) {
$errorMessage = "your access code deactivated..";
}
if not they can register
i tried..but i didn't get idea where i have to add that if..
before i have condition like if number>used it will show some error message like your accesscode limit completed
can anyone help me..
thanks in advance..
= is for value assignment
== is compare two operands
so you need to change
if ( $chk_secret->status='0' ) {
to
if ( $chk_secret->status=='0' ) {
UPDATE:
your query SELECT * FROM {accesscode} WHERE random_no= ? and status=1
which means it going to return only status == 1
you can check with number of rows returned is ZERO then through status zero error message.
Or else
Get rows only based on random_no exists and then check status key
Good Evening,
I'm using CodeIgniter 2 on IIS 8.5 and MSSQL Server,
When i tried to send an email in the process, it shows the error:
Severity: Notice
Message: A non well formed numeric value encountered
Filename: libraries/Email.php
Line Number: 1689
I've been using this code for some projects in the same server, and it's working properly. But when i tried to implement on this one it always shows this error everytime there's sending email process.
And here's my controller:
function reset_pass() {
if (!IS_AJAX) {
display_nonajax_stop();
exit;
} else {
$settings = $this->m_setting->get_setting_array();
$min_pass_length = (int) $settings["acc_pass_min_length"];
$data = $this->input->post();
$id = $data['id'];
$hasil = array();
$kondisi = array(
"usr_id" => $id
);
$current_time = waktu_sekarang();
$baris = $this->m_ess->get_user_employee_row($kondisi);
$user = $baris;
if ($user->usr_email === NULL) {
$hasil['pesan'] = "User does not have valid email associated . Please contact Administrator.";
$hasil['status'] = 0;
} else {
$this->load->helper('email');
if (!valid_email($user->usr_email)) {
$hasil['pesan'] = "User does not have valid email associated . Please contact Administrator.";
$hasil['status'] = 0;
} else {
$hasil['pesan'] = "Username and email is ok";
$hasil['status'] = 0;
$this->load->library('rndconditionpass');
$tmppass = $this->rndconditionpass->get_random_string($min_pass_length);
$new_password = $this->bcrypt->do_hash($tmppass);
$mail_data['random'] = $tmppass;
$mail_data['username'] = $user->usr_name;
$mail_data['full_name'] = $user->emp_name;
$mail_data['password'] = $tmppass;
//prepare data to be used in leo_mail library
$param = array();
$param['recipient'] = $user->usr_email;
$param['content'] = $this->load->view("template/mail/mail_reset_pass", $mail_data, TRUE);
$param['subject'] = "Reset Password";
$this->load->library('leo_mail');
$kirim = $this->leo_mail->kirim($param);
if ($kirim['status'] == 1) {
#password history
$insert_pass = array(
"pas_usr_name" => $user->usr_name,
"pas_password" => $new_password,
"pas_date" => $current_time,
"pas_opid" => $this->session->userdata("usr_name"),
"pas_update" => $current_time
);
$this->m_pass->insert_pass($insert_pass);
$hasil['pesan'] = "Password has been reset and user has been notified via email. ";
$hasil['status'] = 1;
//update the database, store the reset code
$update = array();
$update['usr_last_cpass'] = date("Y-m-d H:i:s");
$update['usr_needchgpwd'] = "Y";
$update["usr_password"] = $new_password;
$kondisi = array("usr_name" => $user->usr_name);
$q = $this->m_ess->update_user($update, $kondisi);
} else {
$hasil['pesan'] = "Fail to send email your password reset code.";
$hasil['status'] = 0;
}
}
}
echo json_encode($hasil);
}
}
and here's the '$this->leo_mail->kirim function
function kirim($param) {
$q=$this->ci->m_smtp->get_mail_konfig();
$hasil=array();
if($q->num_rows()<1) {
$hasil['pesan']="Your SMTP configuration has not been set up properly";
$hasil['status']=0;
} else {
if(valid_email($param['recipient'])) {
$config=array();
$config_data= $q->row();
$config['protocol'] = "smtp";
$config['useragent'] = "HRISSMTPLIB";
$config['smtp_port'] = $config_data->smt_smtp_port;
$config['smtp_host'] = $config_data->smt_smtp_host;
$config['smtp_user']= $config_data->smt_smtp_user;
$config['smtp_pass']= $this->ci->leo_enkripsi->decrypt($config_data->smt_smtp_pass,$this->key);
$config['newline']="\r\n";
$config['wordwrap'] = FALSE;
$config['starttls']=($config_data->smt_encrypt_type==3)?TRUE:FALSE;
$config['mailtype'] = "html";
$this->ci->email->initialize($config);
$this->ci->email->from($config_data->smt_email,$config_data->smt_name);
$this->ci->email->to($param['recipient']);
$this->ci->email->subject($param['subject']);
$this->ci->email->message($param['content']);
if($this->ci->email->send()) {
$hasil['pesan']="Email sent";
$hasil['status']=1;
} else {
$hasil['pesan']= $this->ci->email->print_debugger();
$hasil['status']=0;
}
} else {
$hasil['pesan']="Recipient email is not valid";
$hasil['status']=0;
}
}
return $hasil;
}
Sorry for my bad english.
Thank you in advance.
<?php
require("MySQLDAO.php");
$config = parse_ini_file('../database.ini');
$returnValue = array();
//checking if the information is not empty.
if(empty($_REQUEST["firstname"]) || empty($_REQUEST["lastname"])
|| empty($_REQUEST["address"])|| empty($_REQUEST["postcode"])|| empty($_REQUEST["userid"])){
$returnValue["error"]="Missing information";
$returnValue["message"]="You have not added all the information needed to sign up.";
echo json_encode($returnValue);
return;
}
//protect from sql injections.
$fn = htmlentities($_REQUEST["firstname"]);
$ln = htmlentities($_REQUEST["lastname"]);
$add = htmlentities($_REQUEST["address"]);
$post = htmlentities($_REQUEST["postcode"]);
$userid = htmlentities($_REQUEST["userid"]);
// read ini file which has the keys.
$dbhost = trim($config["dbhost"]);
$dbuser = trim($config["dbuser"]);
$dbpass = trim($config["dbpass"]);
$dbname = trim($config["dbname"]);
$dao = new MySQLDAO($dbhost,$dbuser,$dbpass,$dbname);
$dao ->openConnection();
$userdetails = $dao->postAccDetail($userid);
if (!empty($userdetails))
{
$returnValue["error"]="Error 101";
$returnValue["message"]="You have already submitted to get your accounts through the post.";
echo json_encode($returnValue);
return;
}
//register new user.
$result = $dao ->registerPost($fn,$ln,$add,$post,$userid);
if($result){
$returnValue["Message1"] = "Congratulations!";
$returnValue["Message2"] = "We will be sending your details to you in the next 5 working days.";
}
else{
$returnValue["error"] = "Something went wrong";
$returnValue["Message"] = "Sorry we could not create a profile for you please try again.";
}
$dao ->closeConnection();
echo json_encode($returnValue);
?>
<database file>
public function postAccDetail($userid) {
$returnValue = array();
$sql = "select * from post where userid ='".$userid."'";
$result = $this->conn->query($sql);
if ($result != null && (mysqli_num_rows($result) >= 1)) {
$row = $result->fetch_array(MYSQLI_ASSOC);
if (!empty($row)) {
$returnValue = $row;
}
}
return $returnValue;
}
public function registerPost($fn,$ln,$add,$post,$userid) {
$sql = "insert into post set firstname=?,lastname=?,address=?,postcode=?,userid=?";
$statement = $this->conn->prepare($sql);
if (!$statement)
throw new Exception($statement->error);
//the 5s indicate that the values are going to be strings.
$statement->bind_param("ssssi",$fn,$ln,$add,$post,$userid);
$returnValue = $statement->execute();
return $returnValue;
}
I can't seem to find an error with this code and was wondering if someone could help. when I run the file on my local machine I seem to be fine but when I upload the files to a server I seem to get a failed to load resource i know the database file is correct as other files seem to work fine without a problem.
I've added an image of the database aswell.
Can someone please help me.
In my Yii web application I want to write a web service for mobile application. I create a url for access student details with GET method. That I want to change GET method to POST method or PUT method. My url is,
url/index.php/user/login/studentdetails/?username=demo
I am getting this username from client side and giving the response from server side to client side in json format.
My code is,
public function actionStudentdetails() {
if (isset($_GET['username'])) {
$user = Users::model()->findByAttributes(array('username' => $_GET['username']));
$usertypeid = $user->usertypeid;
if ($usertypeid === '1') {
$studentid = $user->userid;
} else if ($usertypeid === '3') {
$guardianid = $user->userid;
$studentid = $_GET['studentid'];
} else {
$employeemasterid = $user->userid;
}
$student = Student::model()->findByPk($studentid);
header('Content-type: application/json');
$response["student_admissionno"] = $student->student_admissionno;
$response["student_firstname"] = $student->student_firstname;
$response["student_middlename"] = $student->student_middlename;
$response["student_lastname"] = $student->student_lastname;
$response["student_admissiondate"] = $student->student_admissiondate;
$response["student_dob"] = $student->student_dob;
$response["student_gender"] = $student->student_gender;
$response["student_religion"] = $student->student_religion;
$response["student_caste"] = $student->student_caste;
$response["student_address1"] = $student->student_address1;
$response["student_address2"] = $student->student_address2;
$response["student_city"] = $student->student_city;
$response["student_state"] = $student->student_state;
$response["success"] = 1;
$response["message"] = "success";
echo json_encode($response);
}
}
}
Please help me.
you can try this code for webserivce. you can used any method GET or POST Method of data posting in server side.
StudentController.php
public function actionStudentdetails() {
$json_data = array();
$params = isset($_REQUEST) ? $_REQUEST: "";
if (!empty($params)) {
$username = $params['username'];
if($username == "") {
$json_data['success'] = false;
$json_data['message'] = 'Username are required.';
} else {
$user = Users::model()->findByAttributes(array('username' => $params['username']));
$usertypeid = $user->usertypeid;
if ($usertypeid === '1') {
$studentid = $user->userid;
} else if ($usertypeid === '3') {
$guardianid = $user->userid;
$studentid = $_GET['studentid'];
} else {
$employeemasterid = $user->userid;
}
$student = Student::model()->findByPk($studentid);
header('Content-type: application/json');
$json_data["student_admissionno"] = $student->student_admissionno;
$json_data["student_firstname"] = $student->student_firstname;
$json_data["student_middlename"] = $student->student_middlename;
$json_data["student_lastname"] = $student->student_lastname;
$json_data["student_admissiondate"] = $student->student_admissiondate;
$json_data["student_dob"] = $student->student_dob;
$json_data["student_gender"] = $student->student_gender;
$json_data["student_religion"] = $student->student_religion;
$json_data["student_caste"] = $student->student_caste;
$json_data["student_address1"] = $student->student_address1;
$json_data["student_address2"] = $student->student_address2;
$json_data["student_city"] = $student->student_city;
$json_data["student_state"] = $student->student_state;
$json_data['success'] = true;
$json_data['message'] = "Data found Successful.";
}
} else {
$json_data['success'] = false;
$json_data['message'] = "Please try again.";
}
echo json_encode($response);
}