public function get($file, $all = false)
 {
     $subtitlesUrls = array();
     if (!is_file($file)) {
         return $subtitlesUrls;
     }
     $userToken = $this->logIn();
     $hashGenerator = new HashGenerator($file);
     $fileHash = $hashGenerator->get();
     $subtitles = $this->searchSubtitles($userToken, $fileHash, filesize($file));
     $urlGenerator = new UrlGenerator();
     return $urlGenerator->getSubtitleUrls($subtitles, $all);
 }
 public function __invoke()
 {
     $generator = new HashGenerator();
     $i = 1;
     while (true) {
         $hash = $generator->generateHash("ckczppom", $i, "md5");
         echo $i . ": " . $hash . "\n";
         if (substr($hash, 0, 5) !== "00000") {
             $i++;
             continue;
         }
         echo "Lowest integer required to produce a hash starting with five zeroes: " . $i;
         break;
     }
 }
 /**
  * Generate and update User with new password.
  * @param User $user
  * @return string
  */
 private function updateUserPassword(User $user)
 {
     $newPassword = PasswordGenerator::generate();
     $newPasswordHash = HashGenerator::generateMD5($newPassword);
     $user->setPassword($newPasswordHash);
     DAOFactory::getUserDAO()->save($user);
     return $newPassword;
 }
Example #4
0
 public function login($email, $password)
 {
     $user = $this->find($email);
     if ($user) {
         if ($this->userRegisterInfo->password === HashGenerator::createHash($password, $this->userRegisterInfo->salt)) {
             Session::sessionPuts($this->sessionName, $this->userRegisterInfo->email);
             return true;
         }
     }
     return false;
 }
Example #5
0
 public function getTokens($options)
 {
     // Generate merchant hash code
     $hash = \HashGenerator::generate($this->veritrans->merchant_id, $this->veritrans->merchant_hash_key, $this->veritrans->order_id);
     // populate parameters for the post request
     $data = array('version' => $this->veritrans->version, 'merchant_id' => $this->veritrans->merchant_id, 'merchanthash' => $hash, 'order_id' => $this->veritrans->order_id, 'billing_different_with_shipping' => $this->veritrans->billing_different_with_shipping, 'required_shipping_address' => $this->veritrans->required_shipping_address, 'email' => $this->veritrans->email, 'first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'city' => $this->_sanitize($this->veritrans->city, 'city'), 'country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'phone' => $this->_sanitize($this->veritrans->phone, 'phone'), 'finish_payment_return_url' => $this->veritrans->finish_payment_return_url, 'unfinish_payment_return_url' => $this->veritrans->unfinish_payment_return_url, 'error_payment_return_url' => $this->veritrans->error_payment_return_url);
     if ($this->veritrans->required_shipping_address && $this->veritrans->billing_different_with_shipping) {
         $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->shipping_first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->shipping_last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->shipping_address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->shipping_address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->shipping_city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->shipping_country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->shipping_postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->shipping_phone, 'phone')));
     } else {
         if ($this->veritrans->required_shipping_address && !$this->veritrans->billing_different_with_shipping) {
             $data = array_merge($data, array('shipping_first_name' => $this->_sanitize($this->veritrans->first_name, 'name'), 'shipping_last_name' => $this->_sanitize($this->veritrans->last_name, 'name'), 'shipping_address1' => $this->_sanitize($this->veritrans->address1, 'address'), 'shipping_address2' => $this->_sanitize($this->veritrans->address2, 'address'), 'shipping_city' => $this->_sanitize($this->veritrans->city, 'city'), 'shipping_country_code' => $this->_sanitize($this->veritrans->country_code, 'countryCode'), 'shipping_postal_code' => $this->_sanitize($this->veritrans->postal_code, 'postalCode'), 'shipping_phone' => $this->_sanitize($this->veritrans->phone, 'phone')));
         }
     }
     $optional_features = array('enable_3d_secure', 'bank', 'installment_terms', 'promo_bins', 'point_banks', 'payment_methods', 'installment_banks');
     foreach ($optional_features as $feature) {
         if (!is_null($this->veritrans->{$feature})) {
             $data[$feature] = $this->veritrans->{$feature};
         }
     }
     // Populate items
     $data['repeat_line'] = 0;
     foreach ($this->veritrans->items as $item) {
         $item_id[] = $this->_sanitize($item['item_id'], 'itemId');
         $item_name1[] = $this->_sanitize($item['item_name1'], 'itemName');
         $item_name2[] = $this->_sanitize($item['item_name2'], 'itemName');
         $price[] = $this->_sanitize($item['price'], 'price');
         $quantity[] = $item['quantity'];
         $data['repeat_line']++;
     }
     $data['item_id'] = $item_id;
     $data['item_name1'] = $item_name1;
     $data['item_name2'] = $item_name2;
     $data['price'] = $price;
     $data['quantity'] = $quantity;
     // Call Veritrans API
     try {
         $pest = new \PestJSON('');
         $result = $pest->post(self::REQUEST_KEY_URL, $data);
     } catch (Exception $e) {
         throw $e;
     }
     // Check result
     if (!empty($result['token_merchant'])) {
         // OK
         return $result;
     } else {
         // Veritrans doesn't return tokens
         $this->veritrans->errors = $result['errors'];
         return false;
     }
 }
Example #6
0
 public function checkUserRegistered()
 {
     $cookie = $this->requestCookies['token'];
     if ($cookie == '') {
         $cookie = HashGenerator::generateSalt();
         $this->responseCookies->set('token', $cookie, '1 month');
     }
     $user = $this->em->getRepository('Uppu3\\Entity\\User')->findOneBy(array('token' => $cookie));
     if (!$user) {
         $salt = HashGenerator::generateSalt();
         $user = \Uppu3\Helper\UserHelper::saveAnonymousUser($salt, $this->em, $cookie);
     }
     return $user;
 }
Example #7
0
function authenticate(\Slim\Route $route)
{
    $app = \Slim\Slim::getInstance();
    $query = new QueryHandler();
    $auth = new HashGenerator();
    // Getting request headers
    $headers = apache_request_headers();
    $requestURI = $_SERVER['REQUEST_URI'];
    $requestMethod = $app->request->getMethod();
    $params = $route->getParams();
    try {
        $userId = intval($params['userId']);
        if (!$userId > 0) {
            $userId = DEFAULT_USER;
        }
    } catch (Exception $e) {
        $userId = DEFAULT_USER;
    }
    // TEST CODE ****************************
    $testParams = implode(',', getRequestParams());
    echo "<h3>{$testParams}</h3>";
    // END TEST CODE ************************
    // Get Handshake KEY
    if (!isset($headers['Authorization'])) {
        // api key is missing in header
        exitApp(BAD_REQUEST, "Authorization key is misssing");
    }
    // Get User Access Key
    if (!isset($headers['AccessKey']) && $userId !== DEFAULT_USER) {
        // api key is missing in header
        exitApp(BAD_REQUEST, "Access key is misssing");
    }
    $auth_key = $headers['Authorization'];
    @($accessKey = $headers['AccessKey']);
    $stringParams = implode(',', getRequestParams());
    // AUTHORIZE ADMIN OPERATION
    $adminData = "admin" . $requestURI . "#" . $stringParams;
    $adminHash = $auth->getAuthHash($adminData);
    $userData = $userId . $requestURI . "#" . $stringParams;
    // 		echo $userData;
    $userHash = $auth->getAuthHash($userData);
    // route the authorization for USER or ADMIN
    switch ($auth_key) {
        case $adminHash:
            // check if admin is valid
            $admin = $query->getAdmin($accessKey);
            if (empty($admin)) {
                exitApp(UNAUTHORIZED, "Admin not found!");
            }
            //Check admin access level
            if ($admin[ADMIN_FIELDS::ACCESS_LEVEL == "read"] && $requestMethod != "GET") {
                exitApp(UNAUTHORIZED, "Limited admin access !");
            }
            // admin is verified
            break;
        case $userHash:
            //non-user operation
            if ($userId == DEFAULT_USER) {
                break;
            }
            // UserOperatoin: check if user is valid
            $user_array = $query->getUser(array(USER_FIELDS::ACCESS_KEY => $accessKey));
            if (empty($user_array)) {
                exitApp(UNAUTHORIZED, "Invalid access key!");
            }
            if ($user_array[USER_FIELDS::IS_ACTIVE] == false) {
                // if requesting login
                if (strpos($requestURI, 'login') !== false) {
                    $message = "Please activate your account";
                }
                // for other operation
                $message = "Your account has been deactivated.";
                exitApp(UNAUTHORIZED, $message);
            }
            if ($user_array[USER_FIELDS::USER_ID] != $userId) {
                exitApp(UNAUTHORIZED, "You are not authorized to access others data");
            }
            break;
        default:
            exitApp(UNAUTHORIZED, "Invalid authorization key !");
    }
}
Example #8
0
<!-- script set on forum submission -->
<?php 
require_once 'php/InitFiles/Init.php';
// validate on submission
if (ForumInput::forumExists($POST)) {
    if (Token::check(ForumInput::getForumInput('token'))) {
        // validate user input
        $validateRegistry = new ValidateUserInput();
        $passed = $validateRegistry->validateForum($_POST, ValidateUserInput::registryRequirements());
        if ($passed->getValidForum()) {
            // register user into database
            $salt = HashGenerator::createSalt(32);
            $newUserSession = new UserSession();
            $newUserSession->registerUser(array('firstname' => ForumInput::getForumInput($FIRSTNAME), 'lastname' => ForumInput::getForumInput($LASTNAME), 'email' => ForumInput::getForumInput($EMAIL), 'salt' => $salt, 'password' => HashGenerator::createHash(ForumInput::getForumInput($PASSWORD), $salt), 'datejoined' => date('Y-m-d H:i:s'), 'gender' => substr(ForumInput::getForumInput($GENDER), 0, 1)));
            RedirectPage::to('index.php');
        } else {
            print_r($validateRegistry->getErrors());
            echo "Please Try again";
        }
    } else {
        // cross site request forgery
    }
}
?>

<!-- Sign-Up-->
<!-- Front-end -->
<!DOCTYPE html>
<html>
<head>
	<title>Sign Up</title>
 public function getPassword()
 {
     return HashGenerator::generateMD5($this->password);
 }
Example #10
0
 protected static function prepareAuthorizationString(Request $request, Options $options, $rnd)
 {
     $hash = HashGenerator::generateHash($options->getApiKey(), $options->getSecretKey(), $rnd, $request);
     return vsprintf("IYZWS %s:%s", array($options->getApiKey(), $hash));
 }
 /**
  * Making User activation hash.
  * @param User $user
  * @return string
  */
 private function makeActivationHash(User $user)
 {
     return HashGenerator::generateMD5($user->getLogin() . $user->getEmail() . $user->getPassword());
 }
Example #12
0
 /**
  * @param string $algorithm
  * @param string $secret
  */
 public function __construct(string $algorithm, string $secret)
 {
     parent::__construct($algorithm);
     $this->setSecret($secret);
 }
Example #13
0
 public function get_keys()
 {
     // Generate merchant hash code
     $hash = HashGenerator::generate($this->merchant_id, $this->merchant_hash_key, $this->settlement_type, $this->order_id, $this->gross_amount);
     // populate parameters for the post request
     $data = array('SETTLEMENT_TYPE' => '01', 'MERCHANT_ID' => $this->merchant_id, 'ORDER_ID' => $this->order_id, 'SESSION_ID' => $this->session_id, 'GROSS_AMOUNT' => $this->gross_amount, 'PREVIOUS_CUSTOMER_FLAG' => $this->previous_customer_flag, 'CUSTOMER_STATUS' => $this->customer_status, 'MERCHANTHASH' => $hash, 'PROMO_ID' => $this->promo_id, 'CUSTOMER_SPECIFICATION_FLAG' => $this->billing_address_different_with_shipping_address, 'EMAIL' => $this->email, 'FIRST_NAME' => $this->first_name, 'LAST_NAME' => $this->last_name, 'POSTAL_CODE' => $this->postal_code, 'ADDRESS1' => $this->address1, 'ADDRESS2' => $this->address2, 'CITY' => $this->city, 'COUNTRY_CODE' => $this->country_code, 'PHONE' => $this->phone, 'SHIPPING_FLAG' => $this->required_shipping_address, 'SHIPPING_FIRST_NAME' => $this->shipping_first_name, 'SHIPPING_LAST_NAME' => $this->shipping_last_name, 'SHIPPING_ADDRESS1' => $this->shipping_address1, 'SHIPPING_ADDRESS2' => $this->shipping_address2, 'SHIPPING_CITY' => $this->shipping_city, 'SHIPPING_COUNTRY_CODE' => $this->shipping_country_code, 'SHIPPING_POSTAL_CODE' => $this->shipping_postal_code, 'SHIPPING_PHONE' => $this->shipping_phone, 'SHIPPING_METHOD' => $this->shipping_method, 'CARD_NO' => $this->card_no, 'CARD_EXP_DATE' => $this->card_exp_date, 'FINISH_PAYMENT_RETURN_URL' => $this->finish_payment_return_url, 'UNFINISH_PAYMENT_RETURN_URL' => $this->unfinish_payment_return_url, 'ERROR_PAYMENT_RETURN_URL' => $this->error_payment_return_url, 'LANG_ENABLE_FLAG' => $this->lang_enable_flag, 'LANG' => $this->lang, 'enable_3d_secure' => $this->enable_3d_secure);
     // data query string only without commodity
     $query_string = http_build_query($data);
     // Build Commodity
     if (isset($this->commodity)) {
         $commodity_query_string = $this->build_commodity_query_string($this->commodity);
         $query_string = "{$query_string}&{$commodity_query_string}";
     }
     // Build Installment Banks
     if (isset($this->installment_banks)) {
         foreach ($this->installment_banks as $bank) {
             $query_string = "{$query_string}&installment_banks[]={$bank}";
         }
     }
     // Build Installment Terms
     if (isset($this->installment_terms)) {
         foreach ($this->installment_terms as $install) {
             $query_string = "{$query_string}&installment_terms[]={$install}";
         }
     }
     // Build Promo Bins
     if (isset($this->promo_bins)) {
         foreach ($this->promo_bins as $bin) {
             $query_string = "{$query_string}&promo_bins[]={$bin}";
         }
     }
     // Build Point Banks
     if (isset($this->point_banks)) {
         foreach ($this->point_banks as $bank) {
             $query_string = "{$query_string}&point_banks[]={$bank}";
         }
     }
     $client = new Pest(self::REQUEST_KEY_URL);
     $result = $client->post('', $query_string);
     $key = $this->extract_keys_from($result);
     return $key;
 }