/**
  * Encrypts your mail settings
  *
  * @param $username
  *
  * @param $password
  *
  * @param null $callback
  *
  * @return bool
  */
 public static function EncryptMailSettings($username, $password, $callback = null)
 {
     if (FileMethods::FileExists(PathFinder::RealPath('Json/encrypted/mailer_settings.json'))) {
         /**
          * We already have settings!
          */
         return false;
     }
     /**
      * The decryption key
      */
     $key = Random::RandomMD5();
     /**
      * If not, lets create an array, encrypting each value
      */
     $array = ['decryption_key' => $key, 'mailer_settings' => ['username' => Encryption::EncryptString($username, $key), 'password' => Encryption::EncryptString($password, $key)]];
     /**
      * Write file
      */
     JsonWriter::PathWrite('Json/encrypted/mailer_settings.json', $array);
     /**
      * Is there a callback?
      */
     if ($callback != null) {
         call_user_func($callback);
     }
     /**
      * Return true!
      */
     return true;
 }
示例#2
0
 /**
  * Generates a salt
  *
  * @return bool|null|string
  */
 public function GenerateSalt()
 {
     $salt = Random::RandomMD5();
     if ($salt != null) {
         return $salt;
     }
     return false;
 }
 /**
  * Creates a new token for which a user can verify their email
  *
  * @param $user_id
  *
  * @param $user_email
  *
  * @return bool|null|string
  */
 public function CreateToken($user_id, $user_email)
 {
     /**
      * Is this user valid?
      */
     if ($this->user_actions->GetUser($user_id) != null) {
         /**
          * Does this users email match the one we are sending it to?
          */
         if ($this->user_actions->GetEmail($user_id) == $user_email) {
             /**
              * Lets quickly create a new randomised token
              */
             $access_token = Random::RandomMD5();
             /**
              * Lets check the extremely impossible chance that this token is already in use
              */
             if ($this->TokenExists($access_token)) {
                 return false;
             }
             /**
              * Lets now insert the authentication token into the database
              */
             $this->database->InsertAuthenticationToken($user_id, $access_token, $user_email);
             /**
              * Lets return the token to the user
              */
             return $access_token;
         }
     }
     /**
      * For what ever reason, we failed to complete this task
      */
     return false;
 }
示例#4
0
 /**
  * Encrypts and writes our database settings to file
  *
  * @param $username
  *
  * @param $password
  *
  * @param $location
  *
  * @param $address
  *
  * @param $callback
  *
  * @return bool|null
  */
 public function InitializeDatabase($username, $password, $location, $address, $callback = null)
 {
     /**
      * We first check if we already have settings
      */
     if (FileMethods::FileExists(PathFinder::RealPath('Json/encrypted/database_settings.json'))) {
         /**
          * We already have settings!
          */
         return false;
     }
     /**
      * The decryption key
      */
     $key = Random::RandomMD5();
     /**
      * If not, lets create an array, encrypting each value
      */
     $array = ['decryption_key' => $key, 'database_settings' => ['username' => Encryption::EncryptString($username, $key), 'password' => Encryption::EncryptString($password, $key), 'database' => Encryption::EncryptString($location, $key), 'host' => Encryption::EncryptString($address, $key)]];
     /**
      * Write file
      */
     JsonWriter::PathWrite('Json/encrypted/database_settings.json', $array);
     /**
      * Is there a callback?
      */
     if ($callback != null) {
         call_user_func($callback);
     }
     /**
      * Return true!
      */
     return true;
 }