> For the complete documentation index, see [llms.txt](https://ipehr.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ipehr.gitbook.io/docs/concepts/components/users-directory.md).

# Users Directory

The corresponding [Users smart contract](https://github.com/bsn-si/IPEHR-blockchain-indexes/blob/develop/contracts/Users.sol) is used for registration and authentication of users.

### Users

```remix-solidity
enum Role { Patient, Doctor }

mapping (address => User) private usersStore;
mapping (uint64 => address) private userCodes;

struct User {
      bytes32     IDHash;
      Role        role;
      Attribute[] attrs;
}
```

A `passwordHash` is written to the attributes, which is later used for authentication.

A eight-digit numeric code is stored for users with the Doctor role, which is then used for convenient identification of doctors by patients. The code is calculated as follows:

```remix-solidity
uint64 code = uint64(bytes8(IDHash)) % 99999999;
```

### User groups

```remix-solidity
mapping (bytes32 => UserGroup) private userGroups;   // groupIdHash => UserGroup

struct GroupMember {
      bytes32 userIDHash;
      bytes   userIDEncr;    // userID encrypted by group key
}

struct UserGroup {
      Attribute[]   attrs;
      GroupMember[] members;  
}
```
