“Laravel memeriksa kata sandi lama” Kode Jawaban

Laravel Validasi Ubah Kata Sandi

<?php
   
namespace App\Http\Controllers;
   
use Illuminate\Http\Request;
use App\Rules\MatchOldPassword;
use Illuminate\Support\Facades\Hash;
use App\User;
  
class ChangePasswordController extends Controller
{
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this->middleware('auth');
    }
   
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function index()
    {
        return view('changePassword');
    } 
   
    /**
     * Show the application dashboard.
     *
     * @return \Illuminate\Contracts\Support\Renderable
     */
    public function store(Request $request)
    {
        $request->validate([
            'current_password' => ['required', new MatchOldPassword],
            'new_password' => ['required'],
            'new_confirm_password' => ['same:new_password'],
        ]);
   
        User::find(auth()->user()->id)->update(['password'=> Hash::make($request->new_password)]);
   
        dd('Password change successfully.');
    }
}
Rich Ray

Laravel memeriksa kata sandi lama

use Illuminate\Support\Facades\Hash;
$user = User::findOrFail($id);

/*
* Validate all input fields
*/
$request->validate([
    'password' => 'required',
    'new_password' => 'confirmed|max:8|different:password',
]);

if (Hash::check($request->password, $user->password)) { 
   $user->fill([
    'password' => Hash::make($request->new_password)
    ])->save();

    return redirect()->route('your.route')->with('success', 'Password changed');

} else {
    return redirect()->route('your.route')->with('error', 'Password does not match');
}
Aashiq Hasnat

Jawaban yang mirip dengan “Laravel memeriksa kata sandi lama”

Pertanyaan yang mirip dengan “Laravel memeriksa kata sandi lama”

Lebih banyak jawaban terkait untuk “Laravel memeriksa kata sandi lama” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya