简体   繁体   English

检查字符串是否为bcrypt哈希的最简单,最快捷的方法是什么?

[英]What's the easiest and quickest way to check if a string is a bcrypt hash?

I'm writing a unit test that says that user passwords should be hashed using bcrypt. 我正在编写一个单元测试,说明应该使用bcrypt对用户密码进行哈希处理。 To assert this I need to be able to check if a string looks like a bcrypt hash. 为了断言这一点,我需要能够检查一个字符串是否看起来像一个bcrypt哈希。

I can't find a function that tells me what hashing algorithm was used on a string, is there another way to do it other than something like regular expressions? 我找不到一个函数来告诉我在字符串上使用了什么哈希算法,除了正则表达式之外还有另外一种方法吗?

@JimL soultion is a bit limiting, there is a question breaking down the structure of a bcrypt hash. @JimL的灵魂有点限制,有一个问题打破了bcrypt哈希的结构。

$2a$[Cost]$[Base64Salt][Base64Hash]

So depending on your application you can assert the bcrypt identifier $2a and the require costs of the generated hash. 因此,根据您的应用程序,您可以断言bcrypt标识符$2a以及生成的哈希值的需求成本。

See: https://stackoverflow.com/a/10933491/1722719 for full breakdown. 请参阅: https//stackoverflow.com/a/10933491/1722719以获取完整细分。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取给定URL的MIME / Media / Content类型的最简单,最快的方法是什么? - What's the easiest and quickest way to get the MIME/Media/Content type of a given URL? 从特定标签中剥离字符串的最快方法是什么 - What's the quickest way to strip a string from a specific tag Bcrypt哈希检查不起作用 - Bcrypt hash check not working 解析这样的PHP字符串最简单的方法是什么 - what's the easiest way to parse a PHP string like this 在我的html页面上运行小型php脚本的最快,最简单的方法是什么? - What is the quickest and easiest way to run a small php script on my html page? 检查数组中的所有值是否都是数字的最快方法是什么? - What is the Quickest Way to Check If All Values in an Array Are Numeric? 用&#39;替换&#39;\\ n&#39;最简单的方法是 <br> &#39;? - What's the easiest way to replace '\n' with '<br>'? 在ExtJS网格中,将NULL值显示为空字符串而不是“null”字符串的最简单方法是什么? - What's the easiest way to display NULL value as empty string instead of “null” string in an ExtJS grid? 如果我迁移网站,加密密码最安全、最快捷的方法是什么? - What's the safest and quickest way of encrypting a password if I migrate a website? PHP:哈希数据库结果的最快方法? - PHP: Quickest way to hash database result?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM