+ if (false !== $key) {
+ unset($this->backupCodes[$key]);
+ }
+ }
+
+ /**
+ * @return User
+ */
+ public function addClient(Client $client)
+ {
+ $this->clients[] = $client;
+
+ return $this;
+ }
+
+ /**
+ * @return ArrayCollection<Entry>
+ */
+ public function getClients()
+ {
+ return $this->clients;
+ }
+
+ /**
+ * Only used by the API when creating a new user it'll also return the first client (which was also created at the same time).
+ *
+ * @return Client
+ */
+ public function getFirstClient()
+ {
+ if (!empty($this->clients)) {
+ return $this->clients->first();
+ }
+ }
+
+ /**
+ * Try to find a backup code from the list of backup codes of the current user.
+ *
+ * @param string $code Given code from the user
+ *
+ * @return string|false
+ */
+ private function findBackupCode(string $code)
+ {
+ foreach ($this->backupCodes as $key => $backupCode) {
+ // backup code are hashed using `password_hash`
+ // see ConfigController->otpAppAction
+ if (password_verify($code, $backupCode)) {
+ return $key;
+ }