CodeIgniter Forums
Creating SMS OTP Using Shield - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: Creating SMS OTP Using Shield (/showthread.php?tid=92011)



Creating SMS OTP Using Shield - vishwajithkeshan2 - 11-13-2024

Hi,
I'm trying to build a function to send SMS for two-factor authentication (2FA) instead of using email for 2FA. However, I got stuck trying to override the existing authentication handler function, which creates a 6-digit code and sends it to the user's email address. I want to create a new function to replace that. I'm using CI4 + Shield


RE: Creating SMS OTP Using Shield - captain-sensible - 11-14-2024

i create a random 5  numbers , which i  leverage to show images for captcha like this:

Code:
    public function login()
        {
        //        session_start();
        $session = \Config\Services::session();
        $myarray = array( chr(rand(48,57)) , chr(rand(48,57)) , chr(rand(48,57)) , chr(rand(48,57)) , chr(rand(48,57)));
        $_SESSION['captcha']= $myarray;            
              
                $data = [
                'title'  => 'login  page',
                 'captcha'=>$myarray,
                 'date'=>$this->myDate
            
            ];

        
        echo view('usrLogin',$data);
        
    
                                            
                                            
        }


i then check to see if what was show to prospective admin logging in like this:


Code:
public function credentials()

{
    $session = \Config\Services::session();
    $theArray= $_SESSION['captcha'];
    $this->actualCaptcha= implode("",$theArray);
$this->captcha= $this->request->getVar('captcha');
// if above two lines equate to same thing then captcha entered correctly

not exactly what you want but maybe give you an approach based on producing a number then checking


RE: Creating SMS OTP Using Shield - datamweb - 11-30-2024

Please refer to the link below:

https://github.com/codeigniter4/shield/discussions/1230#discussioncomment-11248988