<?php
session_start();
include "include.php";
$ajax_logout = 1;
include "session.php";

if($updte == 1){
    $user_id = $_POST['user_id'];
    $o1 = $factory->get_object($user_id, "users", "user_id");

    if($o1->user_id > 0){
        // Generate 6 digit numeric password as string
        $paswd = strval(rand(100000, 999999));

        // Encrypt password using cpassword function (same as login)
        $encrypted_password = cpassword($paswd);

        // Update password using updater object
        $o1->password = $encrypted_password;
        $updater->update_object($o1, "users");

        $result['error'] = 0;
        $result['new_password'] = $paswd;
        $result['error_msg'] = "New Password is: ".$paswd;
    } else {
        $result['error'] = 1;
        $result['error_msg'] = "User not found";
    }
}else{
    $result['error'] = 1;
    $result['error_msg'] = "Something went wrong. Please try again";
}

echo json_encode($result);
?>