Expected result: The code is always lockCodeLength characters long and doesn't repeat any of the last LOCK_CODE_HISTORY_LENGTH codes.
Actual result: On a retry the code is twice as long and unusable, and recent codes can repeat.
Suggested fix:
while (needGenerate)
{
lockCodeArray.Clear()
for (int i = 0
lockCodeArray.Insert(GetRandomChar().AsciiToString())
lockCode = string.Join("", lockCodeArray)
if (m_LockCodeHistory.GetValues().Find(lockCode) > INDEX_NOT_FOUND)
continue
needGenerate = false
}
m_LockCodeHistory.Add(lockCode)
Also cap the number of retries, and clamp lockCodeLength to the PIN maximum of 6 when the config is loaded.