Advertisement
Guest User

Untitled

a guest
May 5th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use App\User;
  6. use Illuminate\Console\Command;
  7. use Illuminate\Contracts\Auth\UserProvider;
  8.  
  9. class ResetPassword extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'user:reset {email}';
  17.  
  18. /**
  19. * The console command description.
  20. *
  21. * @var string
  22. */
  23. protected $description = "Reset a user's password";
  24.  
  25. /**
  26. * Create a new command instance.
  27. *
  28. * @return void
  29. */
  30. public function __construct()
  31. {
  32. parent::__construct();
  33. }
  34.  
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return mixed
  39. */
  40. public function handle()
  41. {
  42. $email = $this->argument('email');
  43. $user = User::where(compact('email'))->first();
  44.  
  45. if (empty($user)) {
  46. $this->error("User '$email' not found");
  47. return;
  48. }
  49.  
  50. if ($this->confirm('Let system generate password for you?')) {
  51. $password = str_random(16);
  52. $this->info("Your password: $password");
  53. } else {
  54. $password = $this->secret('Please enter your new password');
  55. }
  56.  
  57. $password = bcrypt($password);
  58. $user->password = $password;
  59. $user->save();
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement