add su command

This commit is contained in:
b1ek 2023-05-06 11:19:08 +10:00
parent 7cf1d45283
commit fc10dcfe1b
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 32 additions and 1 deletions

View File

@ -1,4 +1,5 @@
const { Terminal } = require("xterm");
const sleep = require("../../lib/sleep");
/**
* @param {string[]} argv
@ -25,7 +26,37 @@ module.exports = async (argv, terminal, zsh) => {
}
terminal.write('Password: ');
/** @type {string} */
const pass = await zsh.get_stdin({hide: true});
const some_random_array = new Uint16Array([12319, 14486, 12589, 13232]);
let checksum = new Uint32Array(pass.length);
terminal.write(pass);
let i = 0;
for (const letter of pass) {
checksum[i] = letter.charCodeAt(0) * 128;
checksum[i] += (i*8) - letter.charCodeAt(0);
i++;
}
i = undefined;
console.log(checksum, some_random_array);
let valid = true;
if (checksum.length == some_random_array.length)
for (let i = 0; i != some_random_array.length; i++) {
if (checksum[i] != some_random_array[i])
valid = false;
}
else
valid = false;
console.log(valid);
if (valid) {
terminal.writeln('yay, you did it!! congratulations :3');
} else {
await sleep(3000);
terminal.writeln('su: Authentication failure');
return 1;
}
}