Advertisement
Guest User

Untitled

a guest
May 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. contract Title {
  2.  
  3. address owner;
  4. address[2] userIds;
  5.  
  6. /*
  7. * the constructor registers the signature of the contract creator.
  8. * The authority still need to sign the title to authenticate it.
  9. */
  10. function Title() {
  11. owner = msg.sender;
  12. userIds[0] = owner;
  13. }
  14.  
  15. /*
  16. * authenticates a title submitted by a candidate.
  17. */
  18. function authenticate(address authority) {
  19. userIds[1] = authority;
  20. }
  21.  
  22. /*
  23. * verifies if a title is authenticated by both signature.
  24. */
  25. function isAuthenticated() constant returns (bool retVal) {
  26. if (userIds.length == 2) {
  27. return true;
  28. }
  29. return false;
  30. }
  31. }
  32.  
  33. contract User {
  34.  
  35. Profile profile;
  36.  
  37. address username;
  38.  
  39. string userType = "{0}";
  40. string password = "{1}";
  41. string dateOfBirth = "{2}";
  42. string firstName = "{3}";
  43. string lastName = "{4}";
  44. address[] titles;
  45.  
  46. /*
  47. * the constructor set username and profile.
  48. */
  49. function User() {
  50. username = msg.sender;
  51. profile = Profile(firstName, lastName);
  52. }
  53.  
  54. struct Profile {
  55. string firstName;
  56. string lastName;
  57. }
  58.  
  59. /*
  60. * updates profile data.
  61. */
  62. function updateProfile(string firstName, string lastName, string pwd) {
  63. if (authenticate(pwd)) {
  64. profile = Profile(firstName, lastName);
  65. }
  66. }
  67.  
  68. /*
  69. * updates profile data.
  70. */
  71. function updatePassword(string pwd) {
  72. if (authenticate(pwd)) {
  73. password = pwd;
  74. }
  75. }
  76.  
  77. /*
  78. * updates titles list given an already stored title contract.
  79. */
  80. function updateTitlesList(address title, string pwd) {
  81. if (authenticate(pwd)) {
  82. titles[titles.length -1] = title;
  83. }
  84. }
  85.  
  86. /*
  87. * authenticate a user, given a password and the sender address (username).
  88. */
  89. function authenticate(string pwd) constant returns (bool retVal) {
  90. if (msg.sender == username && stringsEqual(pwd, password)) {
  91. return true;
  92. }
  93. return false;
  94. }
  95.  
  96. /*
  97. * check if two strings are equals.
  98. */
  99. function stringsEqual(string memory _a, string storage _b) internal returns (bool) {
  100. bytes memory a = bytes(_a);
  101. bytes storage b = bytes(_b);
  102. if (a.length != b.length)
  103. return false;
  104. // @todo unroll this loop
  105. for (uint i = 0; i < a.length; i ++) {
  106. if (a[i] != b[i]) {
  107. return false;
  108. }
  109. }
  110. return true;
  111. }
  112.  
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement