1 /* 2 * Copyright 2023, Andrew Lindesay <apl@lindesay.co.nz>. 3 * All rights reserved. Distributed under the terms of the MIT License. 4 */ 5 6 7 #include "PasswordRequirements.h" 8 9 // These are keys that are used to store this object's data into a BMessage 10 // instance. 11 12 #define KEY_MIN_PASSWORD_LENGTH "minPasswordLength" 13 #define KEY_MIN_PASSWORD_UPPERCASE_CHAR "minPasswordUppercaseChar" 14 #define KEY_MIN_PASSWORD_DIGITS_CHAR "minPasswordDigitsChar" 15 16 17 PasswordRequirements::PasswordRequirements() 18 : 19 fMinPasswordLength(0), 20 fMinPasswordUppercaseChar(0), 21 fMinPasswordDigitsChar(0) 22 { 23 } 24 25 26 PasswordRequirements::PasswordRequirements(BMessage* from) 27 : 28 fMinPasswordLength(0), 29 fMinPasswordUppercaseChar(0), 30 fMinPasswordDigitsChar(0) 31 { 32 uint32 value; 33 34 if (from->FindUInt32(KEY_MIN_PASSWORD_LENGTH, &value) == B_OK) { 35 fMinPasswordLength = value; 36 } 37 38 if (from->FindUInt32( 39 KEY_MIN_PASSWORD_UPPERCASE_CHAR, &value) == B_OK) { 40 fMinPasswordUppercaseChar = value; 41 } 42 43 if (from->FindUInt32( 44 KEY_MIN_PASSWORD_DIGITS_CHAR, &value) == B_OK) { 45 fMinPasswordDigitsChar = value; 46 } 47 } 48 49 50 PasswordRequirements::~PasswordRequirements() 51 { 52 } 53 54 55 void 56 PasswordRequirements::SetMinPasswordLength(uint32 value) 57 { 58 fMinPasswordLength = value; 59 } 60 61 62 void 63 PasswordRequirements::SetMinPasswordUppercaseChar(uint32 value) 64 { 65 fMinPasswordUppercaseChar = value; 66 } 67 68 69 void 70 PasswordRequirements::SetMinPasswordDigitsChar(uint32 value) 71 { 72 fMinPasswordDigitsChar = value; 73 } 74 75 76 status_t 77 PasswordRequirements::Archive(BMessage* into, bool deep) const 78 { 79 status_t result = B_OK; 80 if (result == B_OK) { 81 result = into->AddUInt32( 82 KEY_MIN_PASSWORD_LENGTH, fMinPasswordLength); 83 } 84 if (result == B_OK) { 85 result = into->AddUInt32( 86 KEY_MIN_PASSWORD_UPPERCASE_CHAR, fMinPasswordUppercaseChar); 87 } 88 if (result == B_OK) { 89 result = into->AddUInt32( 90 KEY_MIN_PASSWORD_DIGITS_CHAR, fMinPasswordDigitsChar); 91 } 92 return result; 93 } 94