Agron2 Password API

GET:: /api/random

Generate Ramdom Password & Argon2 Hash
Endpoint https://agron2.impulse.solutions/api/generate Method GET Parameters `length` => optional (default lenght 8 characters) `type` => required ['argon2i', 'argon2d', 'argon2id'] Sample Request https://argon2.impulse.solutions/api/generate?type=argon2id Success Response {"success":true,"message":"Ramdom Password Generated","type":"argon2i","length":8,"password":"raVb&Jvz","hash":"$argon2i$v=19$m=4096,t=3,p=1$0HNIehqK+9bACeGk/9DvtA$v+jw1iOEbeUFF00n223c3NNezTLPACTbRNH6flA+XIo"} Error Response {"success":false,"message":"API Error Response"}

GET:: /api/generate

Generates Argon2 Hash Password
Endpoint https://agron2.impulse.solutions/api/generate Method GET Parameters `password` => required `type` => required ['argon2i', 'argon2d', 'argon2id'] Sample Request https://argon2.impulse.solutions/api/generate?password=string&type=argon2id Success Response {"success":true,"message":"Password Hash Generated","type":"argon2id","password":"string","hash":"$argon2id$v=19$m=65536,t=3,p=4$No339vLIHI1/Q8tBDTyIng$IQ/NKECldcW8PLj8uYcovkXS318rQi8v2/EuSosglyA"} Error Response {"success":false,"message":"API Error Response"}

POST:: /api/verify

Verify Argon2 Password
Endpoint https://agron2.impulse.solutions/api/verify Method POST Parameters `password` => required `hash` => required Sample Request https://argon2.impulse.solutions/api/verify Success Response {"success":true,"message":"Password Matched"} Error Response {"success":false,"message":"API Error Response"}

PHP Class

                        
class Argon2 {
    private $baseUrl = 'https://argon2.impulse.solutions/api/';
    
    private function postRequest($endPoint, $data) {
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, $endPoint);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            ));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            $response = curl_exec($ch);

            if (curl_errno($ch)) {
            $error = curl_error($ch);
            curl_close($ch);
            $output = ["success"=>false,"message"=>"Unable To Make API Request."];
            return json_encode($output);
            }

            curl_close($ch);

            return $response;

    }
    
    private function getRequest($endPoint) {
            $ch = curl_init();
            
            curl_setopt($ch, CURLOPT_URL, $endPoint);
            curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
            curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            'Content-Type: application/json',
            ));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            $response = curl_exec($ch);

            if (curl_errno($ch)) {
            $error = curl_error($ch);
            curl_close($ch);
            $output = ["success"=>false,"message"=>"Unable To Make API Request."];
            return json_encode($output);
            }

            curl_close($ch);

            return $response;

    }

    public function random($type = 'argon2id', $length = 8) {
        $data['type'] = $type;
        $data['length'] = $length;
        $queryString = http_build_query($data);
        $endPoint = $this->baseUrl . 'generate?'.$queryString;
        return $this->getRequest($endPoint);
    }
    
    public function generate($password, $type = 'argon2id') {
        $data['password'] = $password;
        $data['type'] = $type;
        $queryString = http_build_query($data);
        $endPoint = $this->baseUrl . 'generate?'.$queryString;
        return $this->getRequest($endPoint);
    }
    
    public function verify($hash, $input) {
        $endPoint = $this->baseUrl . 'verify';
        $data['hash'] = $hash;
        $data['input'] = $input;
        return $this->postRequest($endPoint, json_encode($data));
    }
    
}