Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add game pin generation functionality #12

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pages/auth/gamepin/gamepin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function generatePIN() {
let digits = Math.floor(1000 + Math.random() * 9000);

let letters = '';
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
for (let i = 0; i < 3; i++) {
letters += alphabet.charAt(Math.floor(Math.random() * alphabet.length));
}

let pin = digits + letters;

document.getElementById('pinDisplay').value = pin;
sessionStorage.setItem('gamePin', pin);
}
Comment on lines +1 to +14
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Consider using a more secure random generator for PINs.

The current method using Math.random is not cryptographically secure, which might be a concern for the application's security requirements.


window.onload = function () {
let storedPin = sessionStorage.getItem('gamePIN');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Mismatch in case sensitivity for sessionStorage key.

The key 'gamePIN' used in getItem does not match the case of 'gamePin' used in setItem, which could lead to unexpected behavior.

if (storedPin) {
document.getElementById('pinDisplay ').value = storedPin;
}
};
mmpotulo28 marked this conversation as resolved.
Show resolved Hide resolved
17 changes: 17 additions & 0 deletions pages/auth/gamepin/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Game Pin Generation System</title>
<script src="./gamepin.js" defer></script>
</head>
<body>
<h1>Game Pin Generation System</h1>
<form id="pinForm">
<label for="pinDisplay">Generated PIN: </label>
<input type="text" id="pinDisplay" readonly>
<button type="button" onclick="generatePIN()">Generate PIN</button>
</form>
</body>
</html>