Fix error handling to show error when a user enters incorrect Master Password. #4769

This commit is contained in:
Yogesh Mahajan 2023-05-25 18:51:40 +05:30 committed by GitHub
parent 396f6c9d73
commit cb070fc365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 15 deletions

View File

@ -746,12 +746,14 @@ def get_nodes():
def form_master_password_response(existing=True, present=False, errmsg=None,
keyring_name=''):
keyring_name='',
invalid_master_password_hook=False):
return make_json_response(data={
'present': present,
'reset': existing,
'errmsg': errmsg,
'keyring_name': keyring_name,
'invalid_master_password_hook': invalid_master_password_hook,
'is_error': True if errmsg else False
})
@ -893,7 +895,8 @@ def set_master_password():
return form_master_password_response(
existing=False,
present=False,
errmsg=error
errmsg=error,
invalid_master_password_hook=True
)
# Master password is applicable for Desktop mode and in server mode
@ -906,13 +909,15 @@ def set_master_password():
if current_user.masterpass_check is not None and \
data.get('submit_password', False) and \
not validate_master_password(data.get('password')):
errmsg = gettext("Password mismatch error") if \
config.MASTER_PASSWORD_HOOK else \
gettext("Incorrect master password")
errmsg = '' if config.MASTER_PASSWORD_HOOK \
else gettext("Incorrect master password")
invalid_master_password_hook = \
True if config.MASTER_PASSWORD_HOOK else False
return form_master_password_response(
existing=True,
present=False,
errmsg=errmsg
errmsg=errmsg,
invalid_master_password_hook=invalid_master_password_hook
)
# if master password received in request

View File

@ -157,12 +157,12 @@ export function checkMasterPassword(data, masterpass_callback_queue, cancel_call
const api = getApiInstance();
api.post(url_for('browser.set_master_password'), data).then((res)=> {
let isKeyring = res.data.data.keyring_name.length > 0;
if(!res.data.data.present) {
if(res.data.data.is_error){
//show notifier with error
if(!res.data.data.reset){
if (res.data.data.invalid_master_password_hook){
if(res.data.data.is_error){
Notify.error(res.data.data.errmsg);
}else if(res.data.data.errmsg == 'Password mismatch error'){
}else{
Notify.confirm(gettext('Reset Master Password'),
gettext('The master password retrieved from the master password hook utility is different from what was previously retrieved.') + '<br>'
+ gettext('Do you want to reset your master password to match?') + '<br><br>'
@ -179,12 +179,11 @@ export function checkMasterPassword(data, masterpass_callback_queue, cancel_call
return true;
},
function() {/* If user clicks No */ return true;}
);
}
}
else{
);}
}else{
showMasterPassword(res.data.data.reset, res.data.data.errmsg, masterpass_callback_queue, cancel_callback, res.data.data.keyring_name);
}
} else {
masterPassCallbacks(masterpass_callback_queue);
@ -199,7 +198,7 @@ export function checkMasterPassword(data, masterpass_callback_queue, cancel_call
}
// This functions is used to show the master password dialog.
export function showMasterPassword(isPWDPresent, errmsg, masterpass_callback_queue, cancel_callback, keyring_name) {
export function showMasterPassword(isPWDPresent, errmsg, masterpass_callback_queue, cancel_callback, keyring_name='') {
const api = getApiInstance();
let title = keyring_name.length > 0 ? gettext('Migrate Saved Passwords') : isPWDPresent ? gettext('Unlock Saved Passwords') : gettext('Set Master Password');