screen_rotation
Copied to Clipboard
<!DOCTYPE html> <html> <head> <meta charset="UTF-8" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script> </head> <body> <div id="app"></div> <script type="text/babel"> const { useRef, useState } = React; function App() { const [plainPassword, setPlainPassword] = useState('password'); const [hashPassword, setHashPassword] = useState(''); const handlePasswordChange = (event) => { setPlainPassword(event.target.value); }; const generateHashPassword = () => { const encoder = new TextEncoder(); const data = encoder.encode(plainPassword); window.crypto.subtle.digest('SHA-256', data) .then(hash => { const hashArray = Array.from(new Uint8Array(hash)); const hashHex = hashArray.map(byte => byte.toString(16).padStart(2, '0')).join(''); setHashPassword(hashHex); }) .catch(error => console.error('Error generating hash password:', error)); }; return ( <div className='container'> <h3>React Js Generate Hash Password</h3> <input type="password" value={plainPassword} onChange={handlePasswordChange} /> <button onClick={generateHashPassword}>Generate Hash Password</button> <div className='result'>Hashed Password: {hashPassword}</div> </div> ); } ReactDOM.render(<App />, document.getElementById('app')); </script> <style> .container { text-align: center; box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.12), 0 2px 4px 0 rgba(0, 0, 0, 0.24); width: 600px; margin: 0 auto; padding: 20px } input[type="password"] { padding: 10px; border: 1px solid #ccc; border-radius: 4px; width: 250px; margin-bottom: 10px; } button { padding: 10px 20px; background-color: #4CAF50; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; } button:hover { background-color: #45a049; } .result { margin-top: 10px; font-weight: bold; } </style> </body> </html>