You are here

password_field.module in Password Field 8

Same filename and directory in other branches
  1. 7 password_field.module

File

password_field.module
View source
<?php

/**
 * @file
 * Contains password_field.module.
 */
use Drupal\Core\Routing\RouteMatchInterface;

/**
 * Implements hook_help().
 */
function password_field_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {

    // Main module help for the password_field module.
    case 'help.page.password_field':
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
      $output .= '<p>' . t('module that saves password') . '</p>';
      return $output;
    default:
  }
}

/**
 * Helper function to encrypt-decryt data.
 */
function password_field_encrypt_decrypt($action, $string) {
  $output = FALSE;
  $encrypt_method = "AES-256-CBC";
  $secret_key = 'This is my secret key';
  $secret_iv = 'This is my secret iv';

  // Hash.
  $key = hash('sha256', $secret_key);

  // Iv - encrypt method AES-256-CBC expects 16 bytes else you will get a warning.
  $iv = substr(hash('sha256', $secret_iv), 0, 16);
  if ($action == 'encrypt') {
    $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
    $output = base64_encode($output);
  }
  elseif ($action == 'decrypt') {
    $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  }
  return $output;
}

Functions

Namesort descending Description
password_field_encrypt_decrypt Helper function to encrypt-decryt data.
password_field_help Implements hook_help().