[ExecString] combine SplitParameters with identical function of CUtil
[xbmc.git] / xbmc / GUIPassword.cpp
blob2a0d5ec38e3a5b95fd97f338857c04171fdf7d44
1 /*
2 * Copyright (C) 2005-2020 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "GUIPassword.h"
11 #include "FileItem.h"
12 #include "GUIUserMessages.h"
13 #include "ServiceBroker.h"
14 #include "URL.h"
15 #include "Util.h"
16 #include "dialogs/GUIDialogGamepad.h"
17 #include "dialogs/GUIDialogNumeric.h"
18 #include "favourites/FavouritesService.h"
19 #include "guilib/GUIComponent.h"
20 #include "guilib/GUIKeyboardFactory.h"
21 #include "guilib/GUIWindowManager.h"
22 #include "guilib/LocalizeStrings.h"
23 #include "media/MediaLockState.h"
24 #include "messaging/ApplicationMessenger.h"
25 #include "messaging/helpers/DialogOKHelper.h"
26 #include "profiles/ProfileManager.h"
27 #include "profiles/dialogs/GUIDialogLockSettings.h"
28 #include "profiles/dialogs/GUIDialogProfileSettings.h"
29 #include "settings/MediaSourceSettings.h"
30 #include "settings/Settings.h"
31 #include "settings/SettingsComponent.h"
32 #include "utils/StringUtils.h"
33 #include "utils/URIUtils.h"
34 #include "utils/Variant.h"
35 #include "utils/log.h"
36 #include "view/ViewStateSettings.h"
38 #include <utility>
40 using namespace KODI::MESSAGING;
42 CGUIPassword::CGUIPassword(void)
44 iMasterLockRetriesLeft = -1;
45 bMasterUser = false;
47 CGUIPassword::~CGUIPassword(void) = default;
49 template<typename T>
50 bool CGUIPassword::IsItemUnlocked(T pItem,
51 const std::string& strType,
52 const std::string& strLabel,
53 const std::string& strHeading)
55 const std::shared_ptr<CProfileManager> profileManager =
56 CServiceBroker::GetSettingsComponent()->GetProfileManager();
57 if (profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE)
58 return true;
60 while (pItem->m_iHasLock > LOCK_STATE_LOCK_BUT_UNLOCKED)
62 const std::string strLockCode = pItem->m_strLockCode;
63 int iResult = 0; // init to user succeeded state, doing this to optimize switch statement below
64 if (!g_passwordManager.bMasterUser) // Check if we are the MasterUser!
66 if (0 != CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
67 CSettings::SETTING_MASTERLOCK_MAXRETRIES) &&
68 pItem->m_iBadPwdCount >= CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
69 CSettings::SETTING_MASTERLOCK_MAXRETRIES))
71 // user previously exhausted all retries, show access denied error
72 HELPERS::ShowOKDialogText(CVariant{12345}, CVariant{12346});
73 return false;
75 // show the appropriate lock dialog
76 iResult = VerifyPassword(pItem->m_iLockMode, strLockCode, strHeading);
78 switch (iResult)
80 case -1:
81 { // user canceled out
82 return false;
83 break;
85 case 0:
87 // password entry succeeded
88 pItem->m_iBadPwdCount = 0;
89 pItem->m_iHasLock = LOCK_STATE_LOCK_BUT_UNLOCKED;
90 g_passwordManager.LockSource(strType, strLabel, false);
91 CMediaSourceSettings::GetInstance().UpdateSource(strType, strLabel, "badpwdcount",
92 std::to_string(pItem->m_iBadPwdCount));
93 CMediaSourceSettings::GetInstance().Save();
95 // a mediasource has been unlocked successfully
96 // => refresh favourites due to possible visibility changes
97 CServiceBroker::GetFavouritesService().RefreshFavourites();
98 break;
100 case 1:
102 // password entry failed
103 if (0 != CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(
104 CSettings::SETTING_MASTERLOCK_MAXRETRIES))
105 pItem->m_iBadPwdCount++;
106 CMediaSourceSettings::GetInstance().UpdateSource(strType, strLabel, "badpwdcount",
107 std::to_string(pItem->m_iBadPwdCount));
108 CMediaSourceSettings::GetInstance().Save();
109 break;
111 default:
113 // this should never happen, but if it does, do nothing
114 return false;
115 break;
119 return true;
122 bool CGUIPassword::IsItemUnlocked(CFileItem* pItem, const std::string& strType)
124 const std::string strLabel = pItem->GetLabel();
125 std::string strHeading;
126 if (pItem->m_bIsFolder)
127 strHeading = g_localizeStrings.Get(12325); // "Locked! Enter code..."
128 else
129 strHeading = g_localizeStrings.Get(12348); // "Item locked"
131 return IsItemUnlocked<CFileItem*>(pItem, strType, strLabel, strHeading);
134 bool CGUIPassword::IsItemUnlocked(CMediaSource* pItem, const std::string& strType)
136 const std::string strLabel = pItem->strName;
137 const std::string& strHeading = g_localizeStrings.Get(12325); // "Locked! Enter code..."
139 return IsItemUnlocked<CMediaSource*>(pItem, strType, strLabel, strHeading);
142 bool CGUIPassword::CheckStartUpLock()
144 // prompt user for mastercode if the mastercode was set b4 or by xml
145 int iVerifyPasswordResult = -1;
147 const std::string& strHeader = g_localizeStrings.Get(20075); // "Enter master lock code"
149 if (iMasterLockRetriesLeft == -1)
150 iMasterLockRetriesLeft = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES);
152 if (g_passwordManager.iMasterLockRetriesLeft == 0)
153 g_passwordManager.iMasterLockRetriesLeft = 1;
155 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
157 std::string strPassword = profileManager->GetMasterProfile().getLockCode();
159 if (profileManager->GetMasterProfile().getLockMode() == 0)
160 iVerifyPasswordResult = 0;
161 else
163 for (int i=1; i <= g_passwordManager.iMasterLockRetriesLeft; i++)
165 iVerifyPasswordResult = VerifyPassword(profileManager->GetMasterProfile().getLockMode(), strPassword, strHeader);
166 if (iVerifyPasswordResult != 0 )
168 std::string strLabel1;
169 strLabel1 = g_localizeStrings.Get(12343); // "retries left"
170 int iLeft = g_passwordManager.iMasterLockRetriesLeft-i;
171 std::string strLabel = StringUtils::Format("{} {}", iLeft, strLabel1);
173 // PopUp OK and Display: MasterLock mode has changed but no new Mastercode has been set!
174 HELPERS::ShowOKDialogLines(CVariant{12360}, CVariant{12367}, CVariant{strLabel}, CVariant{""});
176 else
177 i=g_passwordManager.iMasterLockRetriesLeft;
181 if (iVerifyPasswordResult == 0)
183 g_passwordManager.iMasterLockRetriesLeft = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES);
184 return true; // OK The MasterCode Accepted! XBMC Can Run!
186 else
188 CServiceBroker::GetAppMessenger()->PostMsg(TMSG_SHUTDOWN); // Turn off the box
189 return false;
193 bool CGUIPassword::SetMasterLockMode(bool bDetails)
195 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
197 CProfile* profile = profileManager->GetProfile(0);
198 if (profile)
200 CProfile::CLock locks = profile->GetLocks();
201 // prompt user for master lock
202 if (CGUIDialogLockSettings::ShowAndGetLock(locks, 12360, true, bDetails))
204 profile->SetLocks(locks);
205 return true;
208 return false;
211 bool CGUIPassword::IsProfileLockUnlocked(int iProfile)
213 bool bDummy;
214 return IsProfileLockUnlocked(iProfile,bDummy,true);
217 bool CGUIPassword::IsProfileLockUnlocked(int iProfile, bool& bCanceled, bool prompt)
219 if (g_passwordManager.bMasterUser)
220 return true;
222 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
224 int iProfileToCheck = iProfile;
225 if (iProfile == -1)
226 iProfileToCheck = profileManager->GetCurrentProfileIndex();
228 if (iProfileToCheck == 0)
229 return IsMasterLockUnlocked(prompt,bCanceled);
230 else
232 const CProfile *profile = profileManager->GetProfile(iProfileToCheck);
233 if (!profile)
234 return false;
236 if (!prompt)
237 return (profile->getLockMode() == LOCK_MODE_EVERYONE);
239 if (profile->getDate().empty() &&
240 (profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE ||
241 profile->getLockMode() == LOCK_MODE_EVERYONE))
243 // user hasn't set a password and this is the first time they've used this account
244 // so prompt for password/settings
245 if (CGUIDialogProfileSettings::ShowForProfile(iProfileToCheck, true))
246 return true;
248 else
250 if (profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE)
251 // prompt user for profile lock code
252 return CheckLock(profile->getLockMode(),profile->getLockCode(),20095,bCanceled);
256 return true;
259 bool CGUIPassword::IsMasterLockUnlocked(bool bPromptUser)
261 bool bDummy;
262 return IsMasterLockUnlocked(bPromptUser,bDummy);
265 bool CGUIPassword::IsMasterLockUnlocked(bool bPromptUser, bool& bCanceled)
267 bCanceled = false;
269 if (iMasterLockRetriesLeft == -1)
270 iMasterLockRetriesLeft = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES);
272 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
274 if ((LOCK_MODE_EVERYONE < profileManager->GetMasterProfile().getLockMode() && !bMasterUser) && !bPromptUser)
276 // not unlocked, but calling code doesn't want to prompt user
277 return false;
280 if (g_passwordManager.bMasterUser || profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE)
281 return true;
283 if (iMasterLockRetriesLeft == 0)
285 UpdateMasterLockRetryCount(false);
286 return false;
289 // no, unlock since we are allowed to prompt
290 const std::string& strHeading = g_localizeStrings.Get(20075);
291 std::string strPassword = profileManager->GetMasterProfile().getLockCode();
293 int iVerifyPasswordResult = VerifyPassword(profileManager->GetMasterProfile().getLockMode(), strPassword, strHeading);
294 if (1 == iVerifyPasswordResult)
295 UpdateMasterLockRetryCount(false);
297 if (0 != iVerifyPasswordResult)
299 bCanceled = true;
300 return false;
303 // user successfully entered mastercode
304 UpdateMasterLockRetryCount(true);
305 return true;
308 void CGUIPassword::UpdateMasterLockRetryCount(bool bResetCount)
310 // \brief Updates Master Lock status.
311 // \param bResetCount masterlock retry counter is zeroed if true, or incremented and displays an Access Denied dialog if false.
312 if (!bResetCount)
314 // Bad mastercode entered
315 if (0 < CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES))
317 // We're keeping track of how many bad passwords are entered
318 if (1 < g_passwordManager.iMasterLockRetriesLeft)
320 // user still has at least one retry after decrementing
321 g_passwordManager.iMasterLockRetriesLeft--;
323 else
325 // user has run out of retry attempts
326 g_passwordManager.iMasterLockRetriesLeft = 0;
327 // Tell the user they ran out of retry attempts
328 HELPERS::ShowOKDialogText(CVariant{12345}, CVariant{12346});
329 return;
332 std::string dlgLine1 = "";
333 if (0 < g_passwordManager.iMasterLockRetriesLeft)
334 dlgLine1 = StringUtils::Format("{} {}", g_passwordManager.iMasterLockRetriesLeft,
335 g_localizeStrings.Get(12343)); // "retries left"
336 // prompt user for master lock code
337 HELPERS::ShowOKDialogLines(CVariant{20075}, CVariant{12345}, CVariant{std::move(dlgLine1)}, CVariant{0});
339 else
340 g_passwordManager.iMasterLockRetriesLeft = CServiceBroker::GetSettingsComponent()->GetSettings()->GetInt(CSettings::SETTING_MASTERLOCK_MAXRETRIES); // user entered correct mastercode, reset retries to max allowed
343 bool CGUIPassword::CheckLock(LockType btnType, const std::string& strPassword, int iHeading)
345 bool bDummy;
346 return CheckLock(btnType,strPassword,iHeading,bDummy);
349 bool CGUIPassword::CheckLock(LockType btnType, const std::string& strPassword, int iHeading, bool& bCanceled)
351 bCanceled = false;
353 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
355 if (btnType == LOCK_MODE_EVERYONE ||
356 strPassword == "-" ||
357 profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE ||
358 g_passwordManager.bMasterUser)
360 return true;
363 const std::string& strHeading = g_localizeStrings.Get(iHeading);
364 int iVerifyPasswordResult = VerifyPassword(btnType, strPassword, strHeading);
366 if (iVerifyPasswordResult == -1)
367 bCanceled = true;
369 return (iVerifyPasswordResult==0);
372 bool CGUIPassword::CheckSettingLevelLock(const SettingLevel& level, bool enforce /*=false*/)
374 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
376 LOCK_LEVEL::SETTINGS_LOCK lockLevel = profileManager->GetCurrentProfile().settingsLockLevel();
378 if (lockLevel == LOCK_LEVEL::NONE)
379 return true;
381 //check if we are already in settings and in an level that needs unlocking
382 int windowID = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow();
383 if ((int)lockLevel-1 <= (short)CViewStateSettings::GetInstance().GetSettingLevel() &&
384 (windowID == WINDOW_SETTINGS_MENU ||
385 (windowID >= WINDOW_SCREEN_CALIBRATION &&
386 windowID <= WINDOW_SETTINGS_MYPVR)))
387 return true; //Already unlocked
389 else if (lockLevel == LOCK_LEVEL::ALL)
390 return IsMasterLockUnlocked(true);
391 else if ((int)lockLevel-1 <= (short)level)
393 if (enforce)
394 return IsMasterLockUnlocked(true);
395 else if (!IsMasterLockUnlocked(false))
397 //Current Setting level is higher than our permission... so lower the viewing level
398 SettingLevel newLevel = (SettingLevel)(short)(lockLevel-2);
399 CViewStateSettings::GetInstance().SetSettingLevel(newLevel);
402 return true;
406 bool IsSettingsWindow(int iWindowID)
408 return (iWindowID >= WINDOW_SCREEN_CALIBRATION && iWindowID <= WINDOW_SETTINGS_MYPVR)
409 || iWindowID == WINDOW_SKIN_SETTINGS;
412 bool CGUIPassword::CheckMenuLock(int iWindowID)
414 bool bCheckPW = false;
415 int iSwitch = iWindowID;
417 // check if a settings subcategory was called from other than settings window
418 if (IsSettingsWindow(iWindowID))
420 int iCWindowID = CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow();
421 if (iCWindowID != WINDOW_SETTINGS_MENU && !IsSettingsWindow(iCWindowID))
422 iSwitch = WINDOW_SETTINGS_MENU;
425 if (iWindowID == WINDOW_MUSIC_NAV)
427 if (CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_HOME)
428 iSwitch = WINDOW_MUSIC_NAV;
431 if (iWindowID == WINDOW_VIDEO_NAV)
433 if (CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() == WINDOW_HOME)
434 iSwitch = WINDOW_VIDEO_NAV;
437 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
439 switch (iSwitch)
441 case WINDOW_SETTINGS_MENU: // Settings
442 return CheckSettingLevelLock(CViewStateSettings::GetInstance().GetSettingLevel());
443 break;
444 case WINDOW_ADDON_BROWSER: // Addons
445 bCheckPW = profileManager->GetCurrentProfile().addonmanagerLocked();
446 break;
447 case WINDOW_FILES: // Files
448 bCheckPW = profileManager->GetCurrentProfile().filesLocked();
449 break;
450 case WINDOW_PROGRAMS: // Programs
451 bCheckPW = profileManager->GetCurrentProfile().programsLocked();
452 break;
453 case WINDOW_MUSIC_NAV: // Music
454 bCheckPW = profileManager->GetCurrentProfile().musicLocked();
455 if (!bCheckPW && !m_strMediaSourcePath.empty()) // check mediasource by path
456 return g_passwordManager.IsMediaPathUnlocked(profileManager, "music");
457 break;
458 case WINDOW_VIDEO_NAV: // Video
459 bCheckPW = profileManager->GetCurrentProfile().videoLocked();
460 if (!bCheckPW && !m_strMediaSourcePath.empty()) // check mediasource by path
461 return g_passwordManager.IsMediaPathUnlocked(profileManager, "video");
462 break;
463 case WINDOW_PICTURES: // Pictures
464 bCheckPW = profileManager->GetCurrentProfile().picturesLocked();
465 break;
466 case WINDOW_GAMES: // Games
467 bCheckPW = profileManager->GetCurrentProfile().gamesLocked();
468 break;
469 case WINDOW_SETTINGS_PROFILES:
470 bCheckPW = true;
471 break;
472 default:
473 bCheckPW = false;
474 break;
476 if (bCheckPW)
477 return IsMasterLockUnlocked(true); //Now let's check the PW if we need!
478 else
479 return true;
482 bool CGUIPassword::LockSource(const std::string& strType, const std::string& strName, bool bState)
484 VECSOURCES* pShares = CMediaSourceSettings::GetInstance().GetSources(strType);
485 bool bResult = false;
486 for (IVECSOURCES it=pShares->begin();it != pShares->end();++it)
488 if (it->strName == strName)
490 if (it->m_iHasLock > LOCK_STATE_NO_LOCK)
492 it->m_iHasLock = bState ? LOCK_STATE_LOCKED : LOCK_STATE_LOCK_BUT_UNLOCKED;
493 bResult = true;
495 break;
498 CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_SOURCES);
499 CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
501 return bResult;
504 void CGUIPassword::LockSources(bool lock)
506 // lock or unlock all sources (those with locks)
507 const char* strTypes[] = {"programs", "music", "video", "pictures", "files", "games"};
508 for (const char* const strType : strTypes)
510 VECSOURCES *shares = CMediaSourceSettings::GetInstance().GetSources(strType);
511 for (IVECSOURCES it=shares->begin();it != shares->end();++it)
512 if (it->m_iLockMode != LOCK_MODE_EVERYONE)
513 it->m_iHasLock = lock ? LOCK_STATE_LOCKED : LOCK_STATE_LOCK_BUT_UNLOCKED;
515 CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0,GUI_MSG_UPDATE_SOURCES);
516 CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
519 void CGUIPassword::RemoveSourceLocks()
521 // remove lock from all sources
522 const char* strTypes[] = {"programs", "music", "video", "pictures", "files", "games"};
523 for (const char* const strType : strTypes)
525 VECSOURCES *shares = CMediaSourceSettings::GetInstance().GetSources(strType);
526 for (IVECSOURCES it=shares->begin();it != shares->end();++it)
527 if (it->m_iLockMode != LOCK_MODE_EVERYONE) // remove old info
529 it->m_iHasLock = LOCK_STATE_NO_LOCK;
530 it->m_iLockMode = LOCK_MODE_EVERYONE;
532 // remove locks from xml
533 CMediaSourceSettings::GetInstance().UpdateSource(strType, it->strName, "lockmode", "0");
536 CMediaSourceSettings::GetInstance().Save();
537 CGUIMessage msg(GUI_MSG_NOTIFY_ALL,0,0, GUI_MSG_UPDATE_SOURCES);
538 CServiceBroker::GetGUI()->GetWindowManager().SendThreadMessage(msg);
541 bool CGUIPassword::IsDatabasePathUnlocked(const std::string& strPath, VECSOURCES& vecSources)
543 const std::shared_ptr<CProfileManager> profileManager = CServiceBroker::GetSettingsComponent()->GetProfileManager();
545 if (g_passwordManager.bMasterUser || profileManager->GetMasterProfile().getLockMode() == LOCK_MODE_EVERYONE)
546 return true;
548 // Don't check plugin paths as they don't have an entry in sources.xml
549 // Base locked status on videos being locked and being in the video
550 // navigation screen (must have passed lock by then)
551 CURL url{strPath};
552 if (url.IsProtocol("plugin"))
553 return !(profileManager->GetCurrentProfile().videoLocked() &&
554 CServiceBroker::GetGUI()->GetWindowManager().GetActiveWindow() != WINDOW_VIDEO_NAV);
556 // try to find the best matching source
557 bool bName = false;
558 int iIndex = CUtil::GetMatchingSource(strPath, vecSources, bName);
560 if (iIndex > -1 && iIndex < static_cast<int>(vecSources.size()))
561 if (vecSources[iIndex].m_iHasLock < LOCK_STATE_LOCKED)
562 return true;
564 return false;
567 bool CGUIPassword::IsMediaPathUnlocked(const std::shared_ptr<CProfileManager>& profileManager,
568 const std::string& strType) const
570 if (!StringUtils::StartsWithNoCase(m_strMediaSourcePath, "root") &&
571 !StringUtils::StartsWithNoCase(m_strMediaSourcePath, "library://"))
573 if (!g_passwordManager.bMasterUser &&
574 profileManager->GetMasterProfile().getLockMode() != LOCK_MODE_EVERYONE)
576 VECSOURCES& vecSources = *CMediaSourceSettings::GetInstance().GetSources(strType);
577 bool bName = false;
578 int iIndex = CUtil::GetMatchingSource(m_strMediaSourcePath, vecSources, bName);
579 if (iIndex > -1 && iIndex < static_cast<int>(vecSources.size()))
581 return g_passwordManager.IsItemUnlocked(&vecSources[iIndex], strType);
586 return true;
589 bool CGUIPassword::IsMediaFileUnlocked(const std::string& type, const std::string& file) const
591 std::vector<CMediaSource>* vecSources = CMediaSourceSettings::GetInstance().GetSources(type);
593 if (!vecSources)
595 CLog::Log(LOGERROR,
596 "{}: CMediaSourceSettings::GetInstance().GetSources(\"{}\") returned nullptr.",
597 __func__, type);
598 return true;
601 // try to find the best matching source for this file
603 bool isSourceName{false};
604 const std::string fileBasePath = URIUtils::GetBasePath(file);
606 int iIndex = CUtil::GetMatchingSource(fileBasePath, *vecSources, isSourceName);
608 if (iIndex > -1 && iIndex < static_cast<int>(vecSources->size()))
609 return (*vecSources)[iIndex].m_iHasLock < LOCK_STATE_LOCKED;
611 return true;
614 void CGUIPassword::OnSettingAction(const std::shared_ptr<const CSetting>& setting)
616 if (setting == NULL)
617 return;
619 const std::string &settingId = setting->GetId();
620 if (settingId == CSettings::SETTING_MASTERLOCK_LOCKCODE)
621 SetMasterLockMode();
624 int CGUIPassword::VerifyPassword(LockType btnType, const std::string& strPassword, const std::string& strHeading)
626 int iVerifyPasswordResult;
627 switch (btnType)
629 case LOCK_MODE_NUMERIC:
630 iVerifyPasswordResult = CGUIDialogNumeric::ShowAndVerifyPassword(const_cast<std::string&>(strPassword), strHeading, 0);
631 break;
632 case LOCK_MODE_GAMEPAD:
633 iVerifyPasswordResult = CGUIDialogGamepad::ShowAndVerifyPassword(const_cast<std::string&>(strPassword), strHeading, 0);
634 break;
635 case LOCK_MODE_QWERTY:
636 iVerifyPasswordResult = CGUIKeyboardFactory::ShowAndVerifyPassword(const_cast<std::string&>(strPassword), strHeading, 0);
637 break;
638 default: // must not be supported, treat as unlocked
639 iVerifyPasswordResult = 0;
640 break;
643 return iVerifyPasswordResult;