Blockchain-based Authentication – 基于区块链的身份验证区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,Blockchain-based Authentication – 基于区块链的身份验证区块链毕设代写 是一篇很好的国外资料

Blockchain-based Authentication

This project shows how the use of Blockchain allows to create a Blockchain-based authentication where the user’s login data hash is stored in a smart contract.


What authentication is

Authentication is a security process through which a proof of identity or ownership is required. It allows a user owning an account login credentials to login to their account while denying access to others. In most cases, the user’s login information are stored in a server, therefore the authentication process is an interaction between the user and a server, and since this can give access to sensitive information, the server in which login credential are stored must be secured. A blockchain-based authentication (BBA) is proposed in order to lower malicious access and increase security to the authentication process.

BBA schema

Blockchain can be defined as a decentralized, distributed and cryptographic secured ledger that allows to record data. One of the most important features of Blockchain is immutability, which prevents to change or alter data once they have been added to the Blockchain. Since data on the Blockchain is immutable, so is information about its owner, therefore, a BBA system can be used to secure authentication process in a decentralized and immutable way. In this project, we propose an authentication schema based on the Blockchain technology. User’s login data are stored as a hash to the Blockchain via a smart contract, and each time a user request an access to a website for example, the hash derived from credentials provided by the user is compared with the hash that is stored in the smart contract, if their is a match then the user is authorized to access the website, if not, then the access is denied. What is interesting with this schema is that the user must be connected with the ethereum address that was used in the sign up process, since this address is used to generate the user’s login hash. The web3 function sign is used to generate a unique signature based on the username and the user’s ethereum address, and the password and a 6 digit code provided by the user are used to generate a ash which, together with the unique signature’s hash are used to generate the final hash that is stored in the smart contract. To generate the same hash, the user must provide correct username, password, 6 digit code and be connected with the right ethereum address to generate the right signature.

BBA smart contract and Javascript validation functions

During sign up process, the user’s login hash must be stored to the smart contract, and since this action writes information on the Blockchain, the user must pay the transaction gas. This could demotivate users to use BBA, however, one can imagine storing this information not in a smart contract, but either on IPFS for public use or to a private Blockchain for business use. The gas fees are paid only for signing up, the login process does not require writing data in the smart contract, however, approving the data signature with the account which is free of gas is required. The smart contract is shown bellow with javascript functions that allow to validate the process.

//=================== // Authentication.sol //===================  // SPDX-License-Identifier: MIT pragma solidity 0.8.6;  /** * @dev smart contract that allows to store login data hash * by Samuel Gwlanold Edoumou */ contract Authentication {     uint256 public nbOfUsers;      struct User {         string signatureHash;         address userAddress;     }      mapping(address => User) private user;      constructor() {         nbOfUsers = 0;     }      function register(string memory _hash) public {         require(             user[msg.sender].userAddress ==                 address(0x0000000000000000000000000000000000000000),             "already registered"         );          user[msg.sender].signatureHash = _hash;         user[msg.sender].userAddress = msg.sender;         nbOfUsers++;     }      function getSignatureHash() public view returns (string memory) {         require(msg.sender == user[msg.sender].userAddress, "Not allowed");          return user[msg.sender].signatureHash;     }      function getUserAddress() public view returns (address) {         return user[msg.sender].userAddress;     } }

//================== // AuthValidation.js //==================  /*  * @dev validates the authentication  * by Samuel Gwlanold Edoumou  */  import SignData from "./SignData";  const AuthValidation = async (   username,   accountAddress,   password,   digiCode,   web3,   contract ) => {   let userAddress = await contract.methods     .getUserAddress()     .call({ from: accountAddress });    if (userAddress.toLowerCase() !== accountAddress.toLowerCase()) {     return false;   } else {     let signedData = await SignData(username, accountAddress, web3);     let passwordDigiCodeHash = await web3.eth.accounts.hashMessage(       password + digiCode     );      let hash = await web3.eth.accounts.hashMessage(       signedData + passwordDigiCodeHash     );      // get hash from the contract     let hashFromContract = await contract.methods       .getSignatureHash()       .call({ from: accountAddress });      if (hash === hashFromContract) {       return true;     } else {       return false;     }   } };  export default AuthValidation;

//====================== // AuthenticationHash.js //======================  /*  * @dev generates the user login hash  * by Samuel Gwlanold Edoumou  */  import SignData from "./SignData";  const AuthenticationHash = async (   username,   accountAddress,   password,   digiCode,   web3 ) => {   let signedMessage = await SignData(username, accountAddress, web3);   let passwordDigiCodeHash = await web3.eth.accounts.hashMessage(     password + digiCode   );    return await web3.eth.accounts.hashMessage(     signedMessage + passwordDigiCodeHash   ); };  export default AuthenticationHash;

//============ // SignData.js //============  /*  * @dev returns the unique hash based on the username and ethereum address  * by Samuel Gwlanold Edoumou  */  const SignData = async (username, accountAddress, web3) => {   let signedData;    await web3.eth.personal.sign(username, accountAddress, (err, signature) => {     if (err) {       signedData = err;     } else {       signedData = web3.eth.accounts.hashMessage(signature);     }   });    return signedData; };  export default SignData;

Diagram

The following diagram shows all steps to generate the user’s login data hash from the username, the password, the 6 digit code and the ethereum address. To register the user must fill a form to provide the username, the password and the 6 digit code, the ethereum address is retrieved directly from the wallet. This address is associated to the username to generate a signature via the web3 function sign, the generated signature is hashed (hash1). The password is associated with the 6 digit code to generate another hash (hash2). The two hashes are combined to generated the final hash that is stored in the smart contract. To login, the user must be connected to the Blockchain with the same address used during registration, and fill the login form with right username, password and the 6 digit code. The back-end code then generates the hash with this login information and compares it with the hash that was stored in the smart contract by the ethereum address which request the login, if the two hashes match, then the user is authorized to login, if not, the access is denied.

区块链blockchain的身份验证” style=”max-width:100%;” alt=”Blockchain-based Authentication – 基于区块链blockchain的身份验证”>


Video

The video of the Decentralized application that shows how the BBA works

Blockchain-based Authentication - 基于<a href=区块链blockchain的身份验证”>

some changes


基于区块链blockchain的身份验证

本项目展示了区块链blockchain的使用如何允许创建基于区块链blockchain的身份验证,其中用户的登录数据散列存储在智能合约中


什么是身份验证

身份验证是一种安全过程,需要身份或所有权证明。它允许拥有帐户登录凭据的用户登录到其帐户,同时拒绝其他用户的访问。在大多数情况下,用户的登录信息存储在服务器中,因此身份验证过程是用户和服务器之间的交互,并且由于这可以访问敏感信息,因此必须保护存储登录凭据的服务器。为了降低恶意访问并提高认证过程的安全性,提出了基于区块链blockchain的认证(BBA)

BBA模式

区块链blockchain可以定义为一个分散、分布式和加密的安全分类账,允许记录数据。区块链blockchain最重要的特征之一是不变性,它防止在数据添加到区块链blockchain后更改或更改数据。由于区块链blockchain上的数据是不可变的,关于其所有者的信息也是不可变的,因此,BBA系统可用于以分散和不可变的方式保护身份验证过程。在本项目中,我们提出了一种基于区块链blockchain技术的认证模式。用户的登录数据通过智能合约存储为区块链blockchain的散列,并且每次用户请求访问网站时,例如,将从用户提供的凭据派生的散列与存储在智能合约中的散列进行比较,如果两者匹配,则授权用户访问网站,如果不匹配,然后访问被拒绝。该模式的有趣之处在于,用户必须与注册过程中使用的以太坊eth地址连接,因为该地址用于生成用户的登录哈希。web3函数签名用于根据用户名和用户的以太坊eth地址生成唯一签名,用户提供的密码和6位代码用于生成ash,该ash与唯一签名的哈希一起用于生成存储在智能合约中的最终哈希。要生成相同的哈希,用户必须提供正确的用户名、密码、6位代码,并连接到正确的以太坊eth地址以生成正确的签名

BBA智能合约和Javascript验证功能

在注册过程中,用户的登录哈希必须存储到智能合约中,并且由于此操作将信息写入区块链blockchain,因此用户必须支付交易费用。这可能会降低用户使用BBA的积极性,但是,可以想象,将这些信息存储在IPF上供公众使用或私有区块链blockchain供商业使用,而不是智能合约中。仅为注册支付燃气费,登录过程不需要在智能合同中写入数据,但需要使用无燃气账户批准数据签名。下面显示了智能合约,其中包含允许验证流程的javascript函数

//=================== // Authentication.sol //===================  // SPDX-License-Identifier: MIT pragma solidity 0.8.6;  /** * @dev smart contract that allows to store login data hash * by Samuel Gwlanold Edoumou */ contract Authentication {     uint256 public nbOfUsers;      struct User {         string signatureHash;         address userAddress;     }      mapping(address => User) private user;      constructor() {         nbOfUsers = 0;     }      function register(string memory _hash) public {         require(             user[msg.sender].userAddress ==                 address(0x0000000000000000000000000000000000000000),             "already registered"         );          user[msg.sender].signatureHash = _hash;         user[msg.sender].userAddress = msg.sender;         nbOfUsers++;     }      function getSignatureHash() public view returns (string memory) {         require(msg.sender == user[msg.sender].userAddress, "Not allowed");          return user[msg.sender].signatureHash;     }      function getUserAddress() public view returns (address) {         return user[msg.sender].userAddress;     } }

//================== // AuthValidation.js //==================  /*  * @dev validates the authentication  * by Samuel Gwlanold Edoumou  */  import SignData from "./SignData";  const AuthValidation = async (   username,   accountAddress,   password,   digiCode,   web3,   contract ) => {   let userAddress = await contract.methods     .getUserAddress()     .call({ from: accountAddress });    if (userAddress.toLowerCase() !== accountAddress.toLowerCase()) {     return false;   } else {     let signedData = await SignData(username, accountAddress, web3);     let passwordDigiCodeHash = await web3.eth.accounts.hashMessage(       password + digiCode     );      let hash = await web3.eth.accounts.hashMessage(       signedData + passwordDigiCodeHash     );      // get hash from the contract     let hashFromContract = await contract.methods       .getSignatureHash()       .call({ from: accountAddress });      if (hash === hashFromContract) {       return true;     } else {       return false;     }   } };  export default AuthValidation;

//====================== // AuthenticationHash.js //======================  /*  * @dev generates the user login hash  * by Samuel Gwlanold Edoumou  */  import SignData from "./SignData";  const AuthenticationHash = async (   username,   accountAddress,   password,   digiCode,   web3 ) => {   let signedMessage = await SignData(username, accountAddress, web3);   let passwordDigiCodeHash = await web3.eth.accounts.hashMessage(     password + digiCode   );    return await web3.eth.accounts.hashMessage(     signedMessage + passwordDigiCodeHash   ); };  export default AuthenticationHash;

//============ // SignData.js //============  /*  * @dev returns the unique hash based on the username and ethereum address  * by Samuel Gwlanold Edoumou  */  const SignData = async (username, accountAddress, web3) => {   let signedData;    await web3.eth.personal.sign(username, accountAddress, (err, signature) => {     if (err) {       signedData = err;     } else {       signedData = web3.eth.accounts.hashMessage(signature);     }   });    return signedData; };  export default SignData;

图表

下图显示了从用户名、密码、6位代码和以太坊eth地址生成用户登录数据哈希的所有步骤。要注册,用户必须填写一张表格,提供用户名、密码和6位代码,以太坊eth地址直接从钱包中检索。此地址与用户名关联,通过web3函数sign生成签名,生成的签名被哈希(hash1)。密码与6位代码关联以生成另一个哈希(hash2)。这两个散列组合生成存储在智能合约中的最终散列。要登录,用户必须使用注册期间使用的相同地址连接到区块链blockchain,并使用正确的用户名、密码和6位代码填写登录表。然后,后端代码使用此登录信息生成哈希,并将其与请求登录的以太坊eth地址存储在智能合约中的哈希进行比较,如果两个哈希匹配,则授权用户登录,如果不匹配,则拒绝访问

区块链blockchain的身份验证” style=”max-width:100%;” alt=”Blockchain-based Authentication – 基于区块链blockchain的身份验证”>


视频

显示BBA如何工作的分散应用程序视频

Blockchain-based Authentication - 基于<a href=区块链blockchain的身份验证”>

some changes

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/24006.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » Blockchain-based Authentication – 基于区块链的身份验证区块链毕设代写

提供最优质的资源集合

立即查看 了解详情