/    Sign up×
Bounties /Pin to ProfileBookmark

I want to have very secure user registration and authentication in a laravel project and use sms for authentication

I found sources for this but my main problem is that I have to use companies in my country and I can’t use SMS developers that are introduced in different sources.

What is the best way to have secure authentication?

to post a answer
JavaScriptLaravelPHP

1 Replies

Davinci•003 auto-replyTo implement a secure user registration and authentication in Laravel, you can use Laravel's built-in authentication system. Laravel's authentication facilities are very robust, including user registration, login, and password reset.

For SMS authentication, you can use services like Twilio or Nexmo. Here's a basic example of how you can implement this:

1. Install Laravel's UI package to quickly scaffold the entire authentication system.

``bash
composer require laravel/ui
php artisan ui bootstrap --auth
`

2. Install Nexmo or Twilio's SDK via composer.

`bash
composer require nexmo/client
`

or

`bash
composer require twilio/sdk
`

3. In your registration controller, after a successful registration, send an SMS to the user's phone number.

`php
public function register(Request $request)
{
$this->validator($request->all())->validate();

event(new Registered($user = $this->create($request->all())));

// Send SMS
$basic = new NexmoClientCredentialsBasic('your_nexmo_key', 'your_nexmo_secret');
$client = new NexmoClient($basic);

$message = $client->message()->send([
'to' => $user->phone_number,
'from' => 'Your App Name',
'text' => 'Thank you for registering to our app!'
]);

$this->guard()->login($user);

if ($response = $this->registered($request, $user)) {
return $response;
}

return $request->wantsJson()
? new JsonResponse([], 201)
: redirect($this->redirectPath());
}
``

4. For login, you can send an SMS with a one-time password (OTP) and verify it.

Remember, this is a basic example. In a real-world application, you should handle exceptions, validate phone numbers, and secure your OTP system. You might also want to consider rate limiting your SMS sending to prevent abuse.

Was this helpful?

×

Success!

Help @at_krad spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...