S
S
Sergey Khlopov2021-02-21 10:22:49
Laravel
Sergey Khlopov, 2021-02-21 10:22:49

How to generate a password during registration and display this password in a letter?

This is what the user registration looks like:

public function store(Request $request)
    {
        $request->validate([
            'name' => 'required|string|max:255',
            'email' => 'required|string|email|max:255|unique:users',
        ]);

        Auth::login($user = User::create([
            'name' => $request->name,
            'email' => $request->email,
            'password' => Hash::make(Str::random()),
        ]));

        event(new Registered($user));

        return [
            'status' => true,
            'url' => RouteServiceProvider::HOME
        ];
    }

The password is hashed, how to display it in the letter that comes to the user? Or is my approach wrong here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kokhan, 2021-02-21
@SkazochNick

Then you can do this
$password = генерируешь пароль
In the store method
'password' => Hash::make($password),
Well, already in the event you send an email to the user with the $password variable
Maybe you can do it somehow differently, but this is the most obvious option

T
the5x, 2021-02-21
@the5x

Why are you sending a hashed password by mail? You are hashing it so that no one knows it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question