/** * @param array $attributes * * @return array */ protected function hashPassword(array $attributes) { if (isset($attributes['password']) && isset($attributes['password_confirmation']) && $attributes['password'] == $attributes['password_confirmation']) { $attributes['password'] = $attributes['password_confirmation'] = $this->hasher->make($attributes['password']); } return $attributes; }
public function fire(array $data) { $this->validator->setScenario('register')->validate($data); $data['password'] = $this->hasher->make($data['password']); $user = $this->userModel->create($data); event(new UserRegistered($user)); return $user; }
/** * Return a hash that has no / in it suited for url generated. * * @param $value * @return string */ protected function hash($value) { $hash = $this->hasher->make($value); while (strpos($hash, '/') !== false) { $hash = $this->hasher->make($value); } return $hash; }
/** * Create a new user in the database. * * @param array $data * @return \Begin\User */ public function create(array $data) { $user = $this->getNew(); $user->name = $data['name']; $user->email = $data['email']; $user->password = $this->hasher->make($data['password']); $user->save(); return $user; }
/** * @param string $email * @param string $password * @param bool $isStaff * * @throws \DomainException * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return User */ public function make(string $email, string $password, bool $isStaff) : User { if (!$this->validate($email, $password)) { throw new DomainException(); } $user = new User(); $user->email = $email; $user->password = $this->hasher->make($password); if ($isStaff) { $staffRole = $this->roleResource->mustFindByName(Role::STAFF); $staffRole->users()->save($user); } return $user; }
public function fire(array $data) { $this->validator->setScenario('recoverPassword')->validate($data); $token = $this->tokenHelper->validate($data['token']); if ($token === false) { $this->response()->errorBadRequest(trans('messages.token_invalid')); } $user = $token->tokenable->first(); if ($user === NULL) { $this->response()->errorBadRequest(trans('messages.token_invalid')); } $user->password = $this->hasher->make($data['password']); $user->save(); $token->delete(); return $user; }
/** * Execute the command. * * @return void */ public function handle(UserRepositoryInterface $users, Hasher $hasher) { if (!($user = $users->findByResetToken($this->token))) { throw new DisplayException('auth::reset.error'); } $users->resetPassword($user, $hasher->make($this->password)); }
public function postReset() { $credentials = $this->request->only('email', 'password', 'password_confirmation', 'token'); $response = $this->password->reset($credentials, function ($user, $password) { $user->password = $this->hasher->make($password); $user->save(); }); switch ($response) { case $this->password->INVALID_PASSWORD: case $this->password->INVALID_TOKEN: case $this->password->INVALID_USER: return $this->redirector->back()->with('error', $this->translator->get($response)); case $this->password->PASSWORD_RESET: return $this->redirector->to('/'); } }
/** * @param Request $request * @param Hasher $hasher * @return mixed|string */ protected function getNewHash(Request $request, Hasher $hasher) { $email = $request->get('email'); $hash = $hasher->make(time() . 'someRandome123string' . $email); $hash = str_replace('/', '_', $hash); return $hash; }
/** * Resets a given users password * * @param User $user * @param $pwd * @return User */ public function resetPassword(User $user, $pwd) { $hashed = $this->hasher->make($pwd); $user->setPassword(new HashedPassword($hashed)); $this->userRepo->update($user); return $user; }
/** * @return \jorenvanhocht\Blogify\Models\Post */ private function storeOrUpdatePost() { if (!empty($this->data->hash)) { $post = $this->post->byHash($this->data->hash); } else { $post = new Post(); $post->hash = $this->blogify->makeHash('posts', 'hash', true); } $post->slug = $this->data->slug; $post->title = $this->data->title; $post->content = $this->data->post; $post->status_id = $this->status->byHash($this->data->status)->id; $post->publish_date = $this->data->publishdate; $post->user_id = $this->user->byHash($this->auth_user->hash)->id; $post->reviewer_id = $this->user->byHash($this->data->reviewer)->id; $post->visibility_id = $this->visibility->byHash($this->data->visibility)->id; $post->category_id = $this->category->byHash($this->data->category)->id; $post->being_edited_by = null; if (!empty($this->data->password)) { $post->password = $this->hash->make($this->data->password); } $post->save(); $post->tag()->sync($this->tags); return $post; }
/** * Reset the given user's password. * * @param \Illuminate\Contracts\Auth\CanResetPassword $user * @param string $password * @return void */ protected function resetPassword($user, $password) { /** @var $user User */ $user->setPassword($this->hasher->make($password)); $this->em->persist($user); $this->em->flush(); Auth::guard($this->getGuard())->login($user); }
/** * @param string $hash * @param \jorenvanhocht\Blogify\Requests\ProfileUpdateRequest $request * @return \Illuminate\Http\RedirectResponse */ public function update($hash, ProfileUpdateRequest $request) { $user = $this->user->byHash($hash); $user->lastname = $request->name; $user->firstname = $request->firstname; $user->username = $request->username; $user->email = $request->email; if ($request->has('newpassword')) { $user->password = $this->hash->make($request->newpassword); } if ($request->hasFile('profilepicture')) { $this->handleImage($request->file('profilepicture'), $user); } $user->save(); $this->tracert->log('users', $user->id, $this->auth_user->id, 'update'); $message = trans('blogify::notify.success', ['model' => 'User', 'name' => $user->fullName, 'action' => 'updated']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.dashboard'); }
public function changePassword(ChangePasswordRequest $request, Auth $auth, Hasher $hash) { $user = $auth->user(); if ($hash->check($request->password, $user->password) == false) { return redirect('changePassword')->withErrors('Senha atual incorreta.'); } $user->password = $hash->make($request->new_password); $user->save(); return redirect('/'); }
/** * Execute the command. * * @param Hasher $hasher * @param UserRepository $users * @return User * @throws UserAlreadyExistsException */ public function handle(Hasher $hasher, UserRepository $users) { try { $users->findByEmail($this->email); throw new UserAlreadyExistsException($this->email); } catch (ModelNotFoundException $e) { $user = User::register($this->name, $this->email, $hasher->make($this->password), 'admin'); $users->save($user); event(new UserWasRegistered($user)); return $user; } }
/** * Allows an admin user to update another user's password * * @param $user_id * @param $new_password * @param bool $logoutTheUser * @return bool */ public function updateAnotherUsersPassword($user_id, $new_password, $logoutTheUser = false) { if ($user_id === $this->user->id) { return $this->updatePassword($new_password, $logoutTheUser); } $user = $this->userRepository->find($user_id, [], true); $user->password = $this->hasher->make($new_password); $this->dataResult = $user->save(); if ($logoutTheUser) { // not implemented yet } return $this->dataResult; }
public function postUpdate(User $user) { if ($user->id == 1) { return $this->redirector->route("user.index"); } $inputs = $this->request->only('email', 'password', 'first_name', 'last_name', 'permissions', 'groups'); $rules = array('email' => array('email'), 'first_name' => array('required', 'alpha'), 'last_name' => array('required', 'alpha'), 'permissions' => array('array'), 'groups' => array('array')); $validator = $this->validator->make($inputs, $rules); if ($validator->fails()) { return $this->redirector->route('user.update', [$user->id])->withErrors($validator)->withInput($inputs); } $user->updateme($this->request->all()); if (strlen($inputs['password']) >= 6) { $user->password = $this->hasher->make($inputs["password"]); $user->save(); } return $this->redirector->route('user.index'); }
/** * @param \jorenvanhocht\Blogify\Requests\UserRequest $data * @param string $hash * @return array */ private function storeOrUpdateUser($data, $hash = null) { $password = null; if (!isset($hash)) { $password = $this->blogify->makeHash(); $user = new User(); $user->hash = $this->blogify->makeHash('users', 'hash', true); $user->password = $this->hash->make($password); $user->username = $this->blogify->generateUniqueUsername($data->name, $data->firstname); $user->lastname = $data->name; $user->firstname = $data->firstname; $user->email = $data->email; } else { $user = $this->user->byHash($hash); } $user->role_id = $this->role->byHash($data->role)->id; $user->save(); return ['user' => $user, 'password' => $password]; }
/** * @param User $user * @param Hasher $hash * @param Dispatcher $events * @return User * @throws Exception */ public function handle(User $user, Hasher $hash, Dispatcher $events) { $connection = $user->getConnection(); $connection->beginTransaction(); //we already have a user with this email. try { if (!$this->user) { $this->user = $user; $this->user->email = $this->email; $this->user->password = $hash->make($this->password); $this->user->save(); } $events->fire(new UserRegistered($this->user, $this->invitation)); $connection->commit(); return $this->user; } catch (Exception $e) { $connection->rollBack(); throw $e; } }
/** * Handle a registration request for the application. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function register(Request $request) { $registerForm = $this->createForm(RegisterType::class, null, array('action' => route('auth.register_check'))); $registerForm->handleRequest($request); if ($request->isMethod('post')) { if ($registerForm->isValid()) { /** @var User $user */ $user = $registerForm->getData(); $user->setPassword($this->hasher->make($user->getPlainPassword())); $user->setApiToken(Uuid::uuid1()); $this->em->persist($user); $this->em->flush(); Auth::guard($this->getGuard())->login($user); return redirect($this->redirectPath()); } } if (property_exists($this, 'registerView')) { return view($this->registerView, array('form' => $registerForm->createView())); } return view('auth.register', array('form' => $registerForm->createView())); }
/** * Update User detail * * @param $user_id * @param array $formData * @param $role * @return bool */ public function update($user_id, array $formData, $role) { $user = $this->find($user_id); $role = $this->role->where('name', $role)->first(); if (!empty($formData['password'])) { $user->password = $this->hash->make($formData['password']); } $user->email = $formData['email']; $user->organization = $formData['organization']; $user->status = $formData['status']; $user->name = $formData['name']; $user->country = $formData['country']; try { if ($user->save()) { $user->roles()->sync([$role->id]); $this->logger->info('User successfully updated.', $formData); return true; } return false; } catch (\Exception $e) { $this->logger->error($e->getMessage()); return false; } }
/** * Create a new user instance after a valid registration. * * @param array $data * @return User */ public function create(array $data) { return $this->users->create(['name' => $data['name'], 'email' => $data['email'], 'password' => $this->hasher->make($data['password'])]); }
/** * Hashes the password, working without the Hash facade if this is an instance outside of Laravel. * @param $value * @return string */ protected function hashPassword($value) { return self::$external ? self::$hasher->make($value) : Hash::make($value); }
/** * 암호화 된 비밀번호 반환 * * @param string $value password * @return string */ public function hash($value) { return $this->hasher->make($value); }
/** * Generate new token with salt * * @param string $salt * * @return string */ private function generateToken($salt = 'Im salt man, Not Sugar!') { $uniqueId = uniqid('token_' . Carbon::now()->timestamp . '_' . $salt, true); return md5($this->hasher->make($uniqueId)); }
protected function mapDataToUserModel(adLDAPUserModel $user, $password) { $model = new UserModel(['username' => $user->getAccountName(), 'password' => $password ? $this->_hasher->make($password) : null]); $model->setUserInfo($user); return $model; }
/** * Run before the command is handled. * * @param Illuminate\Contracts\Hashing\Hasher * @param Cerbero\Auth\Commands\Command $command * @return mixed */ public function before(Hasher $hasher, $command) { if ($hasher->needsRehash($password = $command->attributes['password'])) { $command->attributes['password'] = $hasher->make($password); } }
/** * Hash the given value. * * @param string $value * @param array $options * * @return string */ public function make($value, array $options = []) { return $this->targetHasher->make($value, $options); }
/** * Set the password attribute, storing it as a hash. * * @param string $value */ public function setPasswordAttribute($value) { $this->attributes['password'] = $value ? static::$hasher->make($value) : ''; }
/** * @param UserRequest $request * @param Hasher $hash * @return \Illuminate\View\View */ public function store(UserRequest $request, Hasher $hash) { $this->user->save(['name' => $request->name, 'email' => $request->email, 'password' => $hash->make($request->password)]); return view('user.store'); }