md5加密和sha1加密_sha1,md5,其他加密技术以及如何

md5加密和sha1加密

Today we will talk about cryptography. As we know, cryptography – the set of methods to ensure confidentiality and authenticity of information. Cryptography is even science. Encryption can be reversible (when we can get the source text) and irreversible (when we can can`t get the source text). Today we will talk about using an irreversible encryption methods (like md5, sha, haval, ripemd and others) in web development.

今天我们将讨论密码学。 众所周知,密码学是确保信息机密性和真实性的一组方法。 密码学甚至是科学。 加密可以是可逆的(当我们可以获取源文本时)和不可逆的(当我们无法获取源文本时)。 今天,我们将讨论在Web开发中使用不可逆的加密方法(例如md5,sha,haval,tripmd等)。

Irreversible encryption is most often used to encrypt passwords. All in order not to store passwords as open text. Thus even if your database is hacked – you can be sure that the attacker does not receive a single password. How are we going to check – whether the user enters a password – simply, we will encrypt the entered data too. Of corse, passwords are not the only where encryption is used. We also can encrypt text, files, and after transferring – check for hash sum of sent data. This is just examples of using.

不可逆加密最常用于加密密码。 所有这些都是为了不将密码存储为开放文本。 因此,即使您的数据库遭到黑客攻击,您也可以确保攻击者不会收到一个密码。 我们将如何检查-用户是否输入密码-简单地,我们也会对输入的数据进行加密。 当然,密码并不是唯一使用加密的地方。 我们还可以加密文本,文件,以及在传输之后–检查已发送数据的哈希总和。 这只是使用的例子。

好的,那么如何使用PHP加密文本? 我们可以使用下一个功能: (Ok, so how to encrypt your text using PHP? we can use next functions:)
  • md5 – calculating md5 hash of string (first param – string for encoding).

    md5 –计算字符串的md5哈希(第一个参数–用于编码的字符串)。

  • sha1 – calculating sha1 hash (first param – string).

    sha1 –计算sha1哈希(第一个参数–字符串)。

  • crypt – hashing function, which using standard unix DES-based algorithm or another algorithms available in system (first param – string).

    crypt –散列函数,使用基于标准unix DES的算法或系统中可用的其他算法(第一参数–字符串)。
  • hash – calculating hash using different algorithms (first param – name of algorithm, second – string for encoding), you can get list of possible algorithm via hash_algos() function. A example you can use ‘md5’, ‘sha1’, ‘sha256’, ‘crc32’, ‘ripemd128’ and others. Here are list in >30 different algorithms !

    hash –使用不同算法(第一个参数–算法名称,第二个-编码字符串)计算哈希,您可以通过hash_algos()函数获取可能算法的列表。 例如,您可以使用“ md5”,“ sha1”,“ sha256”,“ crc32”,“ ripemd128”等。 以下是> 30种不同算法的清单!

Ok, here are method how you can using sha1 for validation of passwords

好的,这是可以使用sha1进行密码验证的方法

步骤1.在注册过程中,我们将存储会员密码的sha1哈希: (Step 1. During registration we will store sha1 hash of member`s password:)

$sSha1Pass = sha1($_POST['password']); // and after - store $sSha1Pass value as hash_password of this member
$sSha1Pass = sha1($_POST['password']); // and after - store $sSha1Pass value as hash_password of this member

步骤2.成员验证(登录过程): (Step 2. Validation of members (login processes):)

$sUsername = mysql_real_escape_string($_POST['login_password']);
$sSha1Pass = sha1($_POST['login_password']);
// now - we just looking in database (where we have table with our users) for enterred username:
$sSQL = "SELECT * FROM `users` WHERE `username`='{$sUsername}' LIMIT 1";
// next - executing that SQL via your gateway (mySQL wrap class)
// in result - we have aray - $aUser with its params, now we should just validate him
if ($sUsername != '' && $sSha1Pass == $aUser['password']) {
    // well, user validated, he entered correct password, we allow him to login into system
}
$sUsername = mysql_real_escape_string($_POST['login_password']);
$sSha1Pass = sha1($_POST['login_password']);
// now - we just looking in database (where we have table with our users) for enterred username:
$sSQL = "SELECT * FROM `users` WHERE `username`='{$sUsername}' LIMIT 1";
// next - executing that SQL via your gateway (mySQL wrap class)
// in result - we have aray - $aUser with its params, now we should just validate him
if ($sUsername != '' && $sSha1Pass == $aUser['password']) {
    // well, user validated, he entered correct password, we allow him to login into system
}

相反,sha1(string)我们总是可以使用下一个方法: (Instead sha1(string) we always can using next method:)

$sSha1String = hash('sha1', $sOurString);
$sSha1String = hash('sha1', $sOurString);

This is possible too of course

当然也有可能

结论 (Conclusion)

I hope that you like por articles and this is useful for your projects. Good luck!

我希望您喜欢这篇文章,这对您的项目很有用。 祝好运!

翻译自: https://www.script-tutorials.com/sha1-md5-other-cryptography-and-how-to/

md5加密和sha1加密

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值