Algorithm for password encryption

Source: Internet
Author: User

Encryption principle: Using different encryption algorithms to add salt encryption processing of strings.

    • To prevent the ciphertext from being MD5 by the dictionary for reverse brute force cracking.
    • Encryption Algorithm (RFC 4357) published by the U.S. National Security Agency (NSA) is used to encrypt the encryption algorithm that is created by itself, to avoid security vulnerabilities.
<?php/** * Password encryption algorithm * Encrypt different encryption algorithms for various types of passwords * @author yagas<[email protected]> * @url http://blog.c Sdn.net/yagas * @version 0.1 * @example: * $passwd = new Tpassword (Tpassword::userpassword); * $passwd->encode ("123456"); * $passwd->ckechpassword ("xxxxxx", "123456"); */ class tpassword extends CModel {    /** * Password Salt length * @var int */    Private $_satlslen=5;/** * Salt offset value in ciphertext * @var int */    Private $_offset=Ten;/** * Cryptographic algorithm name * @var string */    Private $_passwordtype;/** * Member Login password * @var string * *    ConstUserPassword ="sha224";/** * Login password * @var string * *    ConstAdminPassword ="snefru256";/** * Pay password * @var string */    ConstPaypassword ="haval128,3"; Public  function __construct( $passwordType ) {        $this->_passwordtype =$passwordType; } Public  function attributenames() {        return Array(); }/** * Encrypt strings * @param string $password strings that need to be encrypted * @param string $satls crypto Salt *  @return String cipher * /     Public  function encode( $password, $satls=null) {        if(Is_null ($satls) ) {$satls="'; while(Strlen ($satls) >$this->_satlslen) {$i= Mt_rand ( $, -);$satls. = Chr ($i); }        }$password= Hash ($this->_passwordtype,$password.$satls);$password= MD5 ($password);$newPassword= substr ($password,0,$this->_offset);$newPassword. = Strtolower ($satls) . Substr$password,$this->_offset);returnSubstr$newPassword,0, +); }/** * Verify that the password is correct * @param string $securtyString key * @param string $password password * @return Boolean * /     Public  function checkpassword( $securtyString, $password ) {        $satls= substr ($securtyString,$this->_offset,$this->_satlslen);$password=$this->encode ($password, Strtoupper ($satls) );return $securtyString==$password; }}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Algorithm for password encryption

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.