Coder Social home page Coder Social logo

otp-generator's Introduction

Hi there ๐Ÿ‘‹

I'm Sesha, Full-Stack web developer, Programmer, Laravel & Symfony Artisan, and Typescript & Vuejs Enthusiast.

  • ๐Ÿ“ซ How to reach me: ... Ping me on twitter: @seshaCS

otp-generator's People

Contributors

rakeshlanjewar avatar sesha008 avatar seshac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

otp-generator's Issues

OTP VERIFIES/VALIDATES ANY VALUE

I'm trying to verify otp with the code of 6 digits and it verifies any random value first time and then give error that otp is is not valid. I'm using this package in laravel 9.19.

It does not increment the no_times_attempt

while we attempt
$verify = Otp::validate($identifier, $otp->token);
It does not increment no_times_attempt field in table.

The code is in OtpGenerator.php is in validate()

if ($otp->token == $token) {
return (object) [
'status' => true,
'message' => 'OTP is valid',
];
}

$otp->increment('no_times_attempted');

but it should be like below for proper functioning:

if ($otp->token == $token) {

$otp->increment('no_times_attempted');

return (object) [
'status' => true,
'message' => 'OTP is valid',
];
}

New OTP should not be generated and updated in DB if maximum number of attempts reached

It does not make sense to update otp in table if maximum number of attempts reached.

the generate function is:

public function generate(string $identifier): object
{
$this->deleteOldOtps();

    $otp = OtpModel::where('identifier', $identifier)->first();
    if ($otp == null) {
        $otp = OtpModel::create([
            'identifier' => $identifier,
            'token' => $this->createPin(),
            'validity' => $this->validity,
            'generated_at' => Carbon::now(),
        ]);
    } else {
        $otp->update([
            'identifier' => $identifier,
            'token' => $this->useSameToken ?  $otp->token :  $this->createPin(),
            'validity' => $this->validity,
            'generated_at' => Carbon::now(),
        ]);
    }

    if ($otp->no_times_generated == $this->maximumOtpsAllowed) {
        return (object) [
            'status' => false,
            'message' => "Reached the maximum times to generate OTP",
        ];
    }

    $otp->increment('no_times_generated');


    return (object) [
        'status' => true,
        'token' => $otp->token,
        'message' => "OTP generated",
    ];
}

but it should be:

public function generate(string $identifier): object
{
$this->deleteOldOtps();

    $otp = OtpModel::where('identifier', $identifier)->first();
    if ($otp == null) {
        $otp = OtpModel::create([
            'identifier' => $identifier,
            'token' => $this->createPin(),
            'validity' => $this->validity,
            'generated_at' => Carbon::now(),
        ]);
    } else {

        if ($otp->no_times_generated == $this->maximumOtpsAllowed) {
            return (object) [
                'status' => false,
                'message' => "Reached the maximum times to generate OTP",
            ];
        }
        
        $otp->update([
            'identifier' => $identifier,
            'token' => $this->useSameToken ?  $otp->token :  $this->createPin(),
            'validity' => $this->validity,
            'generated_at' => Carbon::now(),
        ]);
    }

    $otp->increment('no_times_generated');


    return (object) [
        'status' => true,
        'token' => $otp->token,
        'message' => "OTP generated",
    ];
}

Successful validated tokens should be deleted

In case the otp is only for a specific action the otp should be deleted after successful validation so it can not be validated again.

Ideally, there would be an option which activates this behaviour.

Return value of Seshac\Otp\OtpGenerator::generate() must be an instance of Seshac\Otp\object, instance of stdClass

Thats the error, I am getting.

[2022-02-23 14:15:26] local.ERROR: Return value of Seshac\Otp\OtpGenerator::generate() must be an instance of Seshac\Otp\object, instance of stdClass returned {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Return value of Seshac\Otp\OtpGenerator::generate() must be an instance of Seshac\Otp\object, instance of stdClass returned at /var/www/snap/vendor/seshac/otp-generator/src/OtpGenerator.php:135)
[stacktrace]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.