脚本宝典收集整理的这篇文章主要介绍了zend-framework – 使用Zend_Mail_Transport_Smtp和MD5-Hashed值作为密码,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
用户帐户的密码是md5-hased,smtp-server正在散列收到的值以检查正确的用户名 – 密码kobination.
现在我正在寻找一种设置Zend_Mail_Transport_Smtp的好方法 – 我显然需要明文密码并将其转发到smtp-server,然后将其转换为md5-hash.
但这意味着我必须将用户密码以明文存储在某处,我想避免使用.
有关如何使用zend框架设置webmailer的最佳实践吗?
我唯一的想法是在会话中保存未散列的密码(我的应用程序中的用户帐户与邮件服务器帐户链接),但必须有更好的方法来处理这种情况
>替补信件:
// Store this in the database $pw_rot = str_rot13( "plain_password" ); // use this in the application $pw_plain = str_rot13( "cynva_cnffjbeq" );
我不建议使用str_rot13()
或类似的东西,因为很容易被看到密码的人猜到.
>无键解码/编码:
另一种方法是使用函数解码/编码密码,该函数不需要像Base64这样的密钥:
// store this in the database $pw_base64 = base64_encode( "plain_password" ); // use this in the application $pw_plain = base64_encode( "cGxhaW5fcGFzc3dvcmQ=" );
比上面的更好一些,但我会将其用于测试目的,因为它易于实现和使用.
>使用密钥解码/编码:
class Password { const KEY = 'your_secret_key_for_the_cipher'; // encode the plain text wITh key for storing in the database public function encode( $plain_text ) { // set up the environment $td = mcrypt_module_oPEn( MCRYPT_BLOWFish,'',MCRYPT_MODE_ECB,'' ); $key = substr( self::KEY,mcrypt_enc_get_key_size( $td ) ); $iv_size = mcrypt_enc_get_iv_size( $td ); $iv = mcrypt_create_iv( $iv_size,MCRYPT_RAND ); if( mcrypt_generic_init( $td,$key,$iv ) != -1 ) { $cipher_text = mcrypt_generic( $td,$plain_text ); // clean up the mcrypt enviroment mcrypt_generic_deinit( $td ); mcrypt_module_close( $td ); } // use hex value return bin2hex( $cipher_text ); } // decode the stored cipher text with key to use in the application public function decode( $cipher_text ) { // set up the environment $td = mcrypt_module_open( MCRYPT_BLOWFISH,$iv ) != -1 ) { $plain_text = mdecrypt_generic( $td,pack( "H*",$cipher_text ) ); // clean up the mcrypt environment mcrypt_generic_deinit( $td ); mcrypt_module_close( $td ); } // remove NUL which maybe added by padding the plain_text return rtrim( $plain_text,"\0" ); }
通过这种方式,只有有权访问数据库和源代码的人才能解密密码.在不利方面,您有一个更复杂的应用程序和一点性能影响.您还可以使用其他对称分组密码.
以上是脚本宝典为你收集整理的zend-framework – 使用Zend_Mail_Transport_Smtp和MD5-Hashed值作为密码全部内容,希望文章能够帮你解决zend-framework – 使用Zend_Mail_Transport_Smtp和MD5-Hashed值作为密码所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。