/** * @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; }
/** * 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)); }
/** * @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; }
public function fire(array $data) { $this->validator->setScenario('login')->validate($data); $user = $this->user->where('email', $data['email'])->first(); if (!$this->hasher->check($data['password'], $user->password)) { throw new LoginFailedException(); } return $user; }
/** * 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; }
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('/'); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $post = $this->post->bySlug($request->segment(2)); if ($post->visibility_id == 2) { if (!$this->hash->check(Input::get('password'), $post->password)) { return redirect()->route('blog.askPassword', [$post->slug])->with('wrong_password', 'Please provide a valid password to view this post'); } } return $next($request); }
/** * 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; } }
/** * @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; }
/** * 비회원 작성 글 인증 확인 * * @param ItemEntity $item board item entity * @param string $email email * @param string $certifyKey 인증 암호 * @return bool */ public function verify(ItemEntity $item, $email, $certifyKey) { if ($email != $item->email) { return false; } return $this->hasher->check($certifyKey, $item->certifyKey); }
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; }
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 Board $board board model * @param string $email email * @param string $certifyKey 인증 암호 * @return bool */ public function verify(Board $board, $email, $certifyKey) { if ($email != $board->email) { return false; } return $this->hasher->check($certifyKey, $board->certifyKey); }
/** * @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; }
/** * Validate a user against the given credentials. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $credentials * @return bool */ public function validateCredentials(UserContract $user, array $credentials) { $credentialsValidated = false; // If the user is set AND, either of auth_type 'internal' or with // auth_type unset or null, then validate against the stored // password hash. Otherwise if the LDAP authentication // method is enabled, try it. if (isset($user) && (isset($user->auth_type) && $this->ldapConfig['label_internal'] === $user->auth_type || !isset($user->auth_type))) { $plain = $credentials['password']; $credentialsValidated = $this->hasher->check($plain, $user->getAuthPassword()); } else { if ($this->ldapConfig['enabled'] && $this->ldapConfig['label_ldap'] === $user->auth_type) { // Validate credentials against LDAP/AD server. $credentialsValidated = $this->validateLDAPCredentials($credentials); // If validated and config set to resync group membership on login. if ($credentialsValidated && $this->ldapConfig['resync_on_login']) { // First, revoke membership to all groups marked to 'resync_on_login'. $this->revokeMembership($user); // Then replicate group membership. $this->replicateMembershipFromLDAP($user); } } } return $credentialsValidated; }
/** * Should generate a password if none given. */ public function testGeneratesPasswordIfNoneGiven() { $this->hasher->expects($this->atLeastOnce())->method('make')->with($this->isType('string'))->willReturn($this->generator()->anyString()); $this->userResource->expects($this->atLeastOnce())->method('setAttribute')->withConsecutive($this->anything(), ['password', $this->isType('string')]); $tester = $this->commandTester($this->makeUser); $tester->execute([]); }
/** * 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; }
/** * 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'); }
/** * @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; } }
/** * Delete account * * @param User $user * @param array $data * @return bool */ public function delete(User $user, array $data) { if (!$this->hasher->check($data['password'], $user->password)) { return false; } if ($this->userRepo->delete($user)) { event(new UserWasDeleted($user)); return true; } return false; }
/** * Validate a user against the given credentials. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $credentials * @return bool */ public function validateCredentials(Authenticatable $user, array $credentials) { $credentials = self::initCredentials($credentials); /** * 第三方登录不验证credential, 本地用户验证密码 */ if (in_array($credentials['type'], ['email', 'username', 'phone'])) { $userAuth = UserAuth::where('user_id', $user->id)->where('type', $credentials['type'])->first(); if ($this->hasher->check($credentials['credential'], $userAuth->credential)) { $userAuth->touch(); return true; } else { return false; } } else { return true; } }
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]; }
/** * 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; } }
/** * Validate a user against the given credentials. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $credentials * @return bool */ public function validateCredentials(UserContract $user, array $credentials) { $plain = $credentials['password']; return $this->hasher->check($plain, $user->getAuthPassword()); }
/** * Check if a given password matches the user's password. * * @param string $password * @return boolean */ public function checkPassword($password) { return static::$hasher->check($password, $this->password); }