Итак, я создал клон существующего программного обеспечения Apache Guacamole, без использования каких -либо API и Tomcat. Были использованы только библиотеки, такие как Guacd и Guacamole-Lite. Сейчас я импортирую дамп DB из оригинального гуакамоле S/W до шахты. Свалка успешно. Но я пытаюсь войти в систему через учетные данные администратора Damp DB, я получаю ошибку «Неверные учетные данные».import crypto from 'crypto';
export function verifyGuacamolePassword(password, saltHex, storedHashHex) {
if (!password || typeof password !== 'string' ||
!saltHex || typeof saltHex !== 'string' ||
!storedHashHex || typeof storedHashHex !== 'string') {
return false;
}
try {
const passwordBytes = Buffer.from(password, 'utf8');
if (!/^(?:[0-9a-fA-F]{2})+$/.test(saltHex)) {
console.error('[verifyGuacamolePassword] Invalid SaltHex format. Value:', saltHex);
return false;
}
const saltBytes = Buffer.from(saltHex, 'hex');
// --- HASHING WITH TWO UPDATES ---
const hasher = crypto.createHash('sha256');
hasher.update(saltBytes); // First update with salt
hasher.update(passwordBytes); // Second update with password
const generatedHashBytes = hasher.digest();
// --- END HASHING ---
const generatedHashHex = generatedHashBytes.toString('hex').toLowerCase();
const lowerStoredHashHex = storedHashHex.toLowerCase();
const match = generatedHashHex === lowerStoredHashHex;
return match;
} catch (error) {
console.error('[verifyGuacamolePassword] Error:', error.message, error.stack);
return false;
}
}
export function createGuacamolePassword(password) {
const saltBytes = crypto.randomBytes(32);
const saltHex = saltBytes.toString('hex');
const passwordBytes = Buffer.from(password, 'utf8');
const combinedBytes = Buffer.concat([saltBytes, passwordBytes]);
const hasher = crypto.createHash('sha256');
hasher.update(combinedBytes);
const hashBytes = hasher.digest();
const hashHex = hashBytes.toString('hex');
return { saltHex, hashHex };
}
< /code>
Теперь я не понимаю, где проблема лежит в этом коде. Все инструкции, представленные в документации, касающихся хранения шестнадцатеричного шестигранного и соли, но возникают проблемы. Заранее спасибо!
Подробнее здесь: https://stackoverflow.com/questions/796 ... ot-working