how to update user pass word with existing email and new password in firebase auth code example

Example 1: how to change user password firebase

var user = firebase.auth().currentUser;
var newPassword = getASecureRandomPassword();

user.updatePassword(newPassword).then(function() {
  // Update successful.
}).catch(function(error) {
  // An error happened.
});

Example 2: firebase sign up with email and password

firebase.auth().createUserWithEmailAndPassword(email, password).catch(function(error) {  // Handle Errors here.  var errorCode = error.code;  var errorMessage = error.message;  // ...});email-password.html