Posts

Showing posts from July, 2024

try...finally in JavaScript and TypeScript

Image
 In JavaScript, you can use try...finally to ensure that certain cleanup code runs regardless of whether an error occurs. This is useful for releasing resources like memory, files, or network connections. Example: Using try...finally for Cleanup Here's an example of how you might use try...finally to ensure that a file is closed after it has been read, regardless of whether an error occurs during the reading process: const fs = require ( 'fs' ); function readFile ( filePath ) {   let fileDescriptor ;   try {     fileDescriptor = fs . openSync ( filePath , 'r' );     const buffer = Buffer . alloc ( 1024 );     fs . readSync ( fileDescriptor , buffer , 0 , buffer . length , 0 );     console . log ( buffer . toString ());   }   catch ( error ) {     onsole . error ( 'Error reading file:' , error );   }   finally {     if ( fileDescriptor !== undefined ) {       fs...

Hashing password in Next JS against rainbow table attacks with a salt for login page

If you want to send a username and password to the server side in nextJs and check if it is correct to continue the identification process. In this article I will explain how and explain why it is important to add salt to a salad 😁 First I will explain why hashing passwords with a salt is an effective defense against rainbow table attacks . Here's why: Rainbow Tables Explained : A rainbow table is a precomputed table for reversing cryptographic hash functions, primarily used for cracking password hashes. Suppose an attacker has a database of hashed passwords obtained from a compromised system. If these passwords were hashed without a salt, the attacker could use a rainbow table to look up the hash values and find the corresponding plaintext passwords. Rainbow tables are feasible because they can be precomputed for all possible plaintext passwords up to a certain length and complexity. The Role of Salt : A salt is a random value that is added to the password before it is hashed. Th...