“Laravel Validasi Ubah Kata Sandi” 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

Validasi kata sandi Laravel

        $request->validate([
            'email' =>'required|exists:users',
            'password'=>'required|password'
        ]);
Mohamad

Laravel Validasi Ubah Kata Sandi

<?php
  
namespace App\Rules;
  
use Illuminate\Contracts\Validation\Rule;
use Illuminate\Support\Facades\Hash;
  
class MatchOldPassword implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return Hash::check($value, auth()->user()->password);
    }
   
    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute is match with old password.';
    }
}
Rich Ray

Jawaban yang mirip dengan “Laravel Validasi Ubah Kata Sandi”

Pertanyaan yang mirip dengan “Laravel Validasi Ubah Kata Sandi”

Lebih banyak jawaban terkait untuk “Laravel Validasi Ubah Kata Sandi” di PHP

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya