首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用智能契约进行基于字符串的身份验证是否可行?

使用智能契约进行基于字符串的身份验证是否可行?
EN

Ethereum用户
提问于 2018-03-12 21:35:00
回答 1查看 79关注 0票数 0

我知道网络上的安全是在私钥级别完成的,但我很想知道在智能契约上增加密码/字符串和基于时间的安全级别的安全含义。

简单的实现如下所示:

代码语言:javascript
复制
pragma solidity ^0.4.21;

contract PasswordTimeLock {
    uint timelock;
    bytes32 hashlock;
    address owner;
    string data = "hello world";

    function PasswordTimeLock(string _password) public {
        owner = msg.sender;
        hashlock = keccak256(owner, _password);
    }

    function unlock(string _password) public returns (bool) {
        require(keccak256(owner, _password) == hashlock);
        timelock = now + 20 seconds;
        return true;
    }

    function read() public view returns (string) {
        require(now < timelock);
        return data;
    }
}

是否公开传递给unlock函数或构造函数的实际字符串?

EN

回答 1

Ethereum用户

发布于 2018-03-12 21:50:40

正如smarx在他的评论中所说,任何人都可以读取构造函数中传递的密码。为了直接回答您的问题,是的,传递给unlock的字符串也是公开的。此外,任何人都可以直接从区块链读取data

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/42542

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档