如何在 Laravel Nova 中显示加密字段值?

How can I show encrypted field value in Laravel Nova?

我正在使用 Password::make 字段在 "site" 模型上保存密码值。

然后,当具有正确权限(我已经在使用)的用户按下详细视图或索引视图上的内联按钮 "show password" 时,我想显示解密的密码。

我试过使用:

Text::make('Decrypted', function () {
    return decrypt($this->password);
})

但不幸的是,这给了我一个 "incorrect payload" 错误。

有什么想法吗?

哈希不可逆

您的密码经过哈希处理,加密。

您现在应该 Laravel 使用 一种方式 哈希函数。

A one-way hash function is a mathematical function which takes a plain text input string and converts it into a fixed-length binary sequence. Furthermore, a one-way hash function is designed in such a way that it is hard to reverse the process, that is, to find a string that hashes to a given value (hence the name one-way.) A good hash function also makes it hard to find two strings that would produce the same hash value.

此外

Showing a user's password on screen, especially in a web app, is likely a security vulnerability and may render the system vulnerable to script injection, screen reader, or man in the middle attacks.

Read more