如何制作一个安全的填空口令系统?

How can one make a secure gap-fill password system?

我正在开发一个 php 登录系统,我想知道如何制作一个安全的密码输入系统,要求输入密码的第 1、2 和 8 个字符,就像许多在线的一样银行系统可以。 如何将密码存储为双重加盐哈希值?

我想到的一个想法是将密码的每个字符存储在单独的字段中或序列化:

伪代码:

$password是用户密码,$secret_word是你用来校验单个字符的单词

function get_hashed_characters($password, $secret_word) {
    $char_store = ""

    for every character $char in $secret_word
        $hashed_char = some_hash_function($char + $password)
        $hash_store = $char_store + $hashed_char

    return $hash_store
}

function check_hashed_char($password, $hash_store, $char_index, $char) {
    if len($hash_store) < $char_index * $HASH_LEN + $HASH_LEN return false

    $hashed_char = substr($hash_store, $char_index * $HASH_LEN, $HASH_LEN)

    return true if $hashed_char is equals to some_hash_function($char + $password), false otherwise
}

更新: 正如 C4ud3x 指出的那样,我对要存储的字符与密码

进行哈希处理

这是一个完全不同的解决方案,有时在 Linux 系统上使用:Challenge-Response authentication

HSBC 在其网站上使用这种风格的密码系统:

在他们的应用程序中:)*

联系他们后他们说:

Ensuring the security of our systems is and will continue to be our number one priority.

All the details that are sent to and from our systems are encrypted using high encryption levels. As long as you keep your log on information secret, we can assure you that the service is secure. As you will appreciate, we cannot provide further details about the additional security measures used by Online Banking, as we must protect the integrity of the system.

虽然这可能只是对他们使用 SSL 的引用,但我认为这可能表明他们:

  • 加密数据库中的密码数据
  • 加密数据库中的密码,然后加密整个数据库以提高安全性。

我认为最好的解决方案是 提供的解决方案,因为它不需要加密(如果没有汇丰银行等银行可用的技术,加密可能不太安全)。