public function validate($value, Constraint $constraint) { $value = SecurityHelper::hash_sha256($value); // hash the value of the password in question $valid = $value == $constraint->siteUser->getPassword(); // compare the value of the password with the siteUser's password if (!$valid) { $this->context->addViolation($constraint->message); return; } }
public function testSendInstitutionUserLoginCredentials() { // create temporary 10 character password $temporaryPassword = \substr(SecurityHelper::hash_sha256(time()), 0, 10); // get data for institution $institution = $this->doctrine->getRepository('InstitutionBundle:Institution')->find(1); //get data for institutionUserType $institutionUserType = $this->doctrine->getRepository('UserBundle:InstitutionUserType')->find(1); $user = new InstitutionUser(); $user->setInstitution($institution); $user->setInstitutionUserType($institutionUserType); $user->setEmail('*****@*****.**'); $user->setPassword($temporaryPassword); $user->setFirstName('alnie'); $user->setMiddleName('leones'); $user->setLastName('jacobe'); $user->setStatus('1'); $sendingResult = $this->service->sendInstitutionUserLoginCredentials($user, $temporaryPassword); $this->assertEquals(1, $sendingResult); return $sendingResult; }
public function createInvitationToken($daysofExpiration) { $daysofExpiration = intVal($daysofExpiration); //generate token $generatedToken = SecurityHelper::hash_sha256(date('Ymdhms')); //check if expiration days given is 0|less than 0 if ($daysofExpiration <= 0) { $daysofExpiration = 30; } //generate expiration date $dateNow = new \DateTime('now'); $expirationDate = $dateNow->modify('+' . $daysofExpiration . ' days'); $invitationToken = new InvitationToken(); $invitationToken->setToken($generatedToken); $invitationToken->setExpirationDate($expirationDate); $invitationToken->setStatus(SiteUser::STATUS_ACTIVE); $em = $this->doctrine->getEntityManager(); $em->persist($invitationToken); $em->flush(); return $invitationToken; }
/** * * @param string $email * @param string $password * @return InstitutionUser */ public function findByIdAndPassword($id, $password) { $password = SecurityHelper::hash_sha256($password); $accountData = $this->find(array('id' => $id, 'password' => $password), array('limit' => 1)); if ($accountData) { //return $accountData; // find a institution user $institutionUser = $this->doctrine->getRepository('UserBundle:InstitutionUser')->findActiveUserById($accountData['id']); // populate account data to SiteUser $institutionUser = $this->hydrateAccountData($institutionUser, $accountData); return $institutionUser; } return null; }
/** * @depends testCreate * @param InstitutionUser $user */ public function testFindIdAndPassword(InstitutionUser $user) { $retrievedUser = $this->service->findByIdAndPassword($user->getAccountId(), $this->commonPassword); $this->assertEquals($retrievedUser->getAccountId(), $user->getAccountId()); $this->assertEquals($retrievedUser->getPassword(), SecurityHelper::hash_sha256($this->commonPassword)); // test for wrong password $retrievedUser = $this->service->findByIdAndPassword($user->getAccountId(), $this->commonPassword . '1232143244'); $this->assertNull($retrievedUser); }
/** * Find an AdminUser based on email and password * * @param string $email * @param string $password * @return HealthCareAbroad\UserBundle\Entity\AdminUser */ public function findByEmailAndPassword($email, $password) { // find the account in the global chromedia accounts $password = SecurityHelper::hash_sha256($password); $accountData = $this->find(array('email' => $email, 'password' => $password), array('limit' => 1)); if ($accountData) { // find an institution user $adminUser = $this->doctrine->getRepository('UserBundle:AdminUser')->findActiveUserById($accountData['id']); if ($adminUser) { // populate account data to SiteUser $adminUser = $this->hydrateAccountData($adminUser, $accountData); return $adminUser; } } return null; }
/** * Generate a memcache key using a configuration key * * @param string $key the config memecache key name * @param array $memcacheKeyParameters * @param array $memcacheNamespaceParameters * @throws KeyFactoryException if $key does not exist in MemcacheKeyCollection * @author acgvelarde */ public function generate($key, $memcacheKeyParameters = array(), $memcacheNamespaceParameters = array()) { if (!$this->memcacheKeys->has($key)) { // key is unrecognizable in our compiled collection throw new KeyFactoryException("Cannot generate invalid memcache key {$key}"); } $memcacheKey = $this->memcacheKeys->get($key); $tempPattern = $memcacheKey->getPattern(); // set the pattern to temporary string for manipulation // interpolate the variables of the memcache key pattern with $memcacheKeyParameters $memcacheKeyString = $this->compiler->interpolatePatternVariables($memcacheKey->getPattern(), $memcacheKey->getVariables(), $memcacheKeyParameters); $memcacheNamespaceKeys = array(); // an array holding the processed memcache namespace patterns // prepare the memcache namespaces foreach ($memcacheKey->getNamespaces() as $memcacheNamespace) { // interpolate the variables in the namespace key regex pattern $memcacheNamespaceKeyString = $this->compiler->interpolatePatternVariables($memcacheNamespace->getPattern(), $memcacheNamespace->getVariables(), $memcacheNamespaceParameters); // get version of memcache namespace $version = $this->memcache->get($memcacheNamespaceKeyString); if (!$version) { // generate new version for this namespace and save it to memcache $version = \time(); $this->memcache->set($memcacheNamespaceKeyString, $version); } // append the version to this memcache namespace $memcacheNamespaceKeyString .= '_' . $version; $memcacheNamespaceKeys[] = $memcacheNamespaceKeyString; } $memcacheKeyString = $memcacheKeyString . '_' . \implode('_', $memcacheNamespaceKeys); // check if this key has been generated and saved to memcache before $generatedKeyStorageKey = self::MEMCACHE_GENERATED_KEY_STORAGE_PREFIX . '_' . $memcacheKeyString; $storedMemcachekey = $this->memcache->get($generatedKeyStorageKey); if (!$storedMemcachekey) { // no stored key, let's save this key // hash the string so we can have equal lengths of memcache keys $memcacheKeyString = SecurityHelper::hash_sha256($memcacheKeyString . time()); $this->memcache->set($generatedKeyStorageKey, $memcacheKeyString); } else { $memcacheKeyString = $storedMemcachekey; } return $memcacheKeyString; }
/** * Add new User and Institution * @author Chaztine Blance */ public function addAction(Request $request) { $factory = $this->get('services.institution.factory'); $institution = $factory->createInstance(); $institutionUser = new InstitutionUser(); $this->get('services.contact_detail')->initializeContactDetails($institutionUser, array(ContactDetailTypes::PHONE, ContactDetailTypes::MOBILE)); $form = $this->createForm(new InstitutionUserSignUpFormType(), $institutionUser, array('include_terms_agreement' => false)); if ($request->isMethod('POST')) { $form->bind($request); if ($form->isValid()) { $postData = $request->get('institutionUserSignUp'); $institutionUser = $form->getData(); // initialize required database fields $institution->setName(uniqid()); $institution->setAddress1(''); $institution->setContactEmail(''); $institution->setContactNumber(''); $institution->setDescription(''); $institution->setLogo(null); $institution->setCoordinates(''); $institution->setType(trim($postData['type'])); /* FIX ME! */ $institution->setWebsites(''); $institution->setStatus(InstitutionStatus::getBitValueForInactiveStatus()); $institution->setZipCode(''); $institution->setSignupStepStatus(0); // Temporary Code to mark a newly added institution as added internally. // Added By: Adelbert Silla $institution->setIsFromInternalAdmin(1); $factory->save($institution); // create Institution user $institutionUser = new InstitutionUser(); $institutionUser->setEmail($form->get('email')->getData()); $institutionUser->setFirstName($institution->getName()); $institutionUser->setLastName('Admin'); $institutionUser->setPassword(SecurityHelper::hash_sha256($form->get('password')->getData())); $institutionUser->setInstitution($institution); $institutionUser->setStatus(SiteUser::STATUS_ACTIVE); $this->get('services.contact_detail')->removeInvalidContactDetails($institutionUser); // var_dump($institutionUser->getContactDetails()); exit; // dispatch event $this->get('event_dispatcher')->dispatch(InstitutionBundleEvents::ON_ADD_INSTITUTION, $this->get('events.factory')->create(InstitutionBundleEvents::ON_ADD_INSTITUTION, $institution, array('institutionUser' => $institutionUser))); return $this->redirect($this->generateUrl('admin_institution_add_details', array('institutionId' => $institution->getId()))); } else { } } return $this->render('AdminBundle:Institution:add.html.twig', array('form' => $form->createView(), 'institutionTypes' => InstitutionTypes::getFormChoices())); }
public function encryptPassword($password) { return SecurityHelper::hash_sha256($password); }
private function _generateBearerToken() { return \ChromediaUtilities\Helpers\SecurityHelper::hash_sha256($this->appId . $this->appSecret); }
/** * @PreAuthorize("hasAnyRole('SUPER_ADMIN', 'CAN_MANAGE_INSTITUTION')") * */ public function changePasswordAction() { $accountId = $this->getRequest()->getSession()->get('accountId'); //get user's data $adminUser = $this->get('services.admin_user')->findById($accountId, true); if (!$adminUser) { throw $this->createNotFoundException('Cannot update invalid account'); } $form = $this->createForm(new AdminUserChangePasswordType(), $adminUser); if ($this->getRequest()->isMethod('POST')) { $form->bindRequest($this->getRequest()); if ($form->isValid()) { $adminUser->setPassword(SecurityHelper::hash_sha256($form->get('new_password')->getData())); $adminUser = $this->get('services.admin_user')->update($adminUser); // dispatch event $this->get('event_dispatcher')->dispatch(AdminBundleEvents::ON_CHANGE_PASSWORD_ADMIN_USER, $this->get('events.factory')->create(AdminBundleEvents::ON_CHANGE_PASSWORD_ADMIN_USER, $adminUser)); $this->get('session')->setFlash('success', "Password changed!"); return $this->redirect($this->generateUrl('admin_homepage')); } } return $this->render('AdminBundle:AdminUser:changePassword.html.twig', array('form' => $form->createView())); }