Skip to content

Instantly share code, notes, and snippets.

@EncodeTheCode
Created March 21, 2025 18:45
Show Gist options
  • Save EncodeTheCode/7be8d43a62b2a668a5bf9163cce115c1 to your computer and use it in GitHub Desktop.
Save EncodeTheCode/7be8d43a62b2a668a5bf9163cce115c1 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Reader</title>
<script>
// Extend HTMLInputElement prototype
HTMLInputElement.prototype.getPasswordValue = function() {
if (this.type === "password") {
return String(this.value); // Ensure the return value is a string
} else {
console.warn("This function is intended for password fields only.");
return "";
}
};
function readPassword() {
let passwordField = document.getElementById("password");
alert("Password value: " + passwordField.getPasswordValue());
}
</script>
</head>
<body>
<label for="password">Enter Password:</label>
<input type="password" id="password">
<button onclick="readPassword()">Read Password</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment