diff --git a/app/Console/Commands/ResetPassword.php b/app/Console/Commands/ResetPassword.php new file mode 100644 index 0000000..57f38e9 --- /dev/null +++ b/app/Console/Commands/ResetPassword.php @@ -0,0 +1,71 @@ +info('Type in the email of the user you would like to reset'); + + $email = $this->ask('Email'); + + $validator = Validator::make([ + 'email' => $email + ], [ + 'email' => 'email', + ]); + + if ($validator->fails()) { + $this->error($validator->errors()->first()); + return Command::FAILURE; + } + + $user = User::where('email', $email)->first(); + + if ($user === null) { + $this->error('User does not exist.'); + return Command::FAILURE; + } + + $this->info('Type in a new password'); + $password = $this->secret('Password'); + $password2 = $this->secret('Re-entered password'); + + if ($password !== $password2) { + $this->error('Re-entered password does not match password'); + return Command::FAILURE; + } + + $user->password = Hash::make($password); + $user->save(); + + return Command::SUCCESS; + } + +}