寻找 PHP 的 crypt() 函数的 Go 等效项
PHP 和 Golang 中的 Crypt 函数
问题介绍
PHP crypt() 函数使用指定的算法生成给定字符串的哈希值。最近出现了一个问题,寻找与此函数等效的 Golang,该函数将为特定输入和哈希值生成相同的结果。
不成功的尝试
进行了多次尝试来实现Go 相当于 PHP 的 crypt() 函数:
- 尝试 1: go-crypt 模块没有产生相同的结果。
- 尝试 2 : 使用 C 互操作性定义自定义 crypt 函数也失败。
- 尝试 3: bcrypt 包不支持 PHP5.3 及更早版本使用的 CRYPT_BLOWFISH 算法。
解决方案
尽管没有找到确切的“Go crypt function”等效项,但发现了替代方案:
- 使用 golang.org/x/crypto/bcrypt 包中,bcrypt.CompareHashAndPassword() 函数可用于比较纯文本密码与哈希值。
示例
可以使用以下Go代码:
<code class="go">import "golang.org/x/crypto/bcrypt" check := bcrypt.CompareHashAndPassword([]byte("a$f5561d2634fb28a969f2dO8QeQ70f4bjCnF/.GvPpjj.8jgmtzZP2"), []byte("enter-new-password")) log.Println(check)</code>
如果“enter-new-password”的bcrypt版本与提供的哈希值相同,则此代码将返回nil;
补充说明
- PHP 的 crypt() 函数支持多种哈希算法,包括 sha256、sha512、blowfish 等。
- 在 Go 中,使用 bcrypt 包时需要显式指定哈希类型和成本。
- 对于问题中的具体场景,$2a$ 作为前缀的存在哈希值建议使用 Blowfish 类型哈希。
以上是Go 中是否存在与 PHP 的 crypt() 函数等价的函数?的详细内容。更多信息请关注PHP中文网其他相关文章!

Toensureinitfunctionsareeffectiveandmaintainable:1)Minimizesideeffectsbyreturningvaluesinsteadofmodifyingglobalstate,2)Ensureidempotencytohandlemultiplecallssafely,and3)Breakdowncomplexinitializationintosmaller,focusedfunctionstoenhancemodularityandm

goisidealforbeginnersandsubableforforcloudnetworkservicesduetoitssimplicity,效率和concurrencyFeatures.1)installgromtheofficialwebsitealwebsiteandverifywith'.2)

开发者应遵循以下最佳实践:1.谨慎管理goroutines以防止资源泄漏;2.使用通道进行同步,但避免过度使用;3.在并发程序中显式处理错误;4.了解GOMAXPROCS以优化性能。这些实践对于高效和稳健的软件开发至关重要,因为它们确保了资源的有效管理、同步的正确实现、错误的适当处理以及性能的优化,从而提升软件的效率和可维护性。

Goexcelsinproductionduetoitsperformanceandsimplicity,butrequirescarefulmanagementofscalability,errorhandling,andresources.1)DockerusesGoforefficientcontainermanagementthroughgoroutines.2)UberscalesmicroserviceswithGo,facingchallengesinservicemanageme

我们需要自定义错误类型,因为标准错误接口提供的信息有限,自定义类型能添加更多上下文和结构化信息。1)自定义错误类型能包含错误代码、位置、上下文数据等,2)提高调试效率和用户体验,3)但需注意其复杂性和维护成本。

goisidealforbuildingscalablesystemsduetoitssimplicity,效率和建筑物内currencysupport.1)go'scleansyntaxandaxandaxandaxandMinimalisticDesignenhanceProductivityAndRedCoductivityAndRedCuceErr.2)ItSgoroutinesAndInesAndInesAndInesAndineSandChannelsEnablenableNablenableNableNablenableFifficConcurrentscorncurrentprogragrammentworking torkermenticmminging

Initfunctionsingorunautomationbeforemain()andareusefulforsettingupenvorments和InitializingVariables.usethemforsimpletasks,避免使用辅助效果,andbecautiouswithTestingTestingTestingAndLoggingTomaintAnainCodeCodeCodeClarityAndTestesto。

goinitializespackagesintheordertheordertheyimported,thenexecutesInitFunctionswithinApcageIntheirdeFinityOrder,andfilenamesdetermineTheOrderAcractacractacrosmultiplefiles.thisprocessCanbeCanbeinepessCanbeInfleccessByendercrededBydeccredByDependenciesbetenciesbetencemendencenciesbetnependendpackages,whermayleLeadtocomplexinitialitialializizesizization


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。

ZendStudio 13.5.1 Mac
功能强大的PHP集成开发环境

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具