<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Shreyansi Shrestha</title>
    <description>The latest articles on Forem by Shreyansi Shrestha (@shreyansii).</description>
    <link>https://forem.com/shreyansii</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2588904%2Fd3590e8a-a11f-4144-938c-bd1c5e7df528.jpg</url>
      <title>Forem: Shreyansi Shrestha</title>
      <link>https://forem.com/shreyansii</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/shreyansii"/>
    <language>en</language>
    <item>
      <title>Building a Secure Password Reset System with Node.js and MySQL</title>
      <dc:creator>Shreyansi Shrestha</dc:creator>
      <pubDate>Wed, 12 Mar 2025 01:52:38 +0000</pubDate>
      <link>https://forem.com/shreyansii/building-a-secure-password-reset-system-with-nodejs-and-mysql-9l1</link>
      <guid>https://forem.com/shreyansii/building-a-secure-password-reset-system-with-nodejs-and-mysql-9l1</guid>
      <description>&lt;p&gt;&lt;em&gt;In this guide, we'll walk through implementing a password reset feature using Node.js, Express, MySQL, and bcrypt. This will ensure users can securely reset their passwords through an email token-based system.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Setting Up the Node.js Project&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start by installing the required dependencies:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install express mysql bcrypt ejs body-parser
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;express – Framework for handling HTTP requests&lt;br&gt;
mysql – To interact with MySQL database&lt;br&gt;
bcrypt – For hashing passwords securely&lt;br&gt;
ejs – To render views&lt;br&gt;
body-parser – To parse form data&lt;/p&gt;

&lt;p&gt;Next, create an index.js file and set up the server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const express = require('express');
const mysql = require('mysql');
const bcrypt = require('bcrypt');
const bodyParser = require('body-parser');

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));

const db = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: '',
    database: 'mydb'
});

db.connect(err =&amp;gt; {
    if (err) throw err;
    console.log('Connected to MySQL');
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Validating the Reset Token&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When a user clicks the "Forgot Password" link, they receive a token via email. The API must verify that token before allowing a password reset.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const resetPasswordLoad = (req, res) =&amp;gt; {
    const token = req.query.token;
    if (!token) return res.render('404');

    db.query('SELECT * FROM password_resets WHERE token=? LIMIT 1', [token], (err, result) =&amp;gt; {
        if (err || result.length === 0) return res.render('404');

        db.query('SELECT * FROM users WHERE email=? LIMIT 1', [result[0].email], (err, user) =&amp;gt; {
            if (err) return res.render('404');
            res.render('reset-password', { user: user[0] });
        });
    });
};


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Retrieves the token from the URL&lt;/li&gt;
&lt;li&gt;Checks if it exists in the password_resets table&lt;/li&gt;
&lt;li&gt;If valid, fetches the corresponding user and renders the password 
reset form&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;3. Creating the Reset Password Form&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create views/reset-password.ejs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;form action="/reset-password" method="POST"&amp;gt;
    &amp;lt;input type="hidden" name="email" value="&amp;lt;%= user.email %&amp;gt;" /&amp;gt;
    &amp;lt;label&amp;gt;New Password:&amp;lt;/label&amp;gt;
    &amp;lt;input type="password" name="password" required /&amp;gt;
    &amp;lt;button type="submit"&amp;gt;Reset Password&amp;lt;/button&amp;gt;
&amp;lt;/form&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Updating the Password in MySQL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Handle the password update in index.js:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;app.post('/reset-password', (req, res) =&amp;gt; {
    const { email, password } = req.body;

    if (!password) {
        return res.render('message', { message: 'Password cannot be empty!' });
    }

    const hashedPassword = bcrypt.hashSync(password, 10);

    db.query('UPDATE users SET password=? WHERE email=?', [hashedPassword, email], (err) =&amp;gt; {
        if (err) return res.render('message', { message: 'Error updating password.' });

        db.query('DELETE FROM password_resets WHERE email=?', [email], () =&amp;gt; {
            res.render('message', { message: 'Password reset successful! You can now log in.' });
        });
    });
});

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Hashes the new password before updating it&lt;/li&gt;
&lt;li&gt;Deletes the password reset token after a successful reset&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;5. Displaying Success/Error Messages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Create views/message.ejs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;% if (message) { %&amp;gt;
    &amp;lt;h2&amp;gt;&amp;lt;%= message %&amp;gt;&amp;lt;/h2&amp;gt;
&amp;lt;% } %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;6. Running the Server&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Start the Node.js server:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node index.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, the password reset system is functional!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;While working on the password reset system in Node.js and MySQL, I wanted to ensure both security and efficiency. Using verification tokens added a layer of authentication, while hashed passwords protected user data. Additionally, implementing proper validation helped prevent errors and improve reliability. This approach made the system more robust and user-friendly.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>mysql</category>
    </item>
    <item>
      <title>{ Understanding PROPS in React.js }</title>
      <dc:creator>Shreyansi Shrestha</dc:creator>
      <pubDate>Fri, 03 Jan 2025 11:53:01 +0000</pubDate>
      <link>https://forem.com/shreyansii/props-in-reactjs-k9</link>
      <guid>https://forem.com/shreyansii/props-in-reactjs-k9</guid>
      <description>&lt;p&gt;PROPS meaning properties in React.js, and these properties/property can be passed from one component to another component ( for example : a property passed from parent component to the child component).&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;These properties are read-only.&lt;/li&gt;
&lt;li&gt;Through these, parent component can send data to child component.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F724i674inxlu62v7hv1k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F724i674inxlu62v7hv1k.jpg" alt="Image description" width="800" height="1777"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can we in the above picture, App.jsx is the parent component and Student.jsx is the child component. The key-value pair  (name="Spongebob") from parent component is being passed to child component 'Student', and then that key value pair gets stored in PROPS object. &lt;/p&gt;

&lt;p&gt;Now, to have the value of name from PROPS object, we use props.name and that is what we can see is done in the child component Student. So, this way we can retrieve value in child component from parent component ( via PROPS object).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In App.jsx :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9h3s3xpk0b3yyzr2nsnw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F9h3s3xpk0b3yyzr2nsnw.png" alt="Image description" width="395" height="227"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In Student.jsx :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpo953soli9wjrcaw7dnc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpo953soli9wjrcaw7dnc.png" alt="Image description" width="349" height="229"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;In localhost :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8sxgy59i2zf30urkuuw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz8sxgy59i2zf30urkuuw.png" alt="Image description" width="144" height="189"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, this is a topic in React.js that took me quite some time to understand and grasp the concept, but at the end, the satistaction of finally understanding it made all that effort worth it.&lt;/p&gt;

</description>
      <category>react</category>
      <category>reactjsdevelopment</category>
      <category>javascriptlibraries</category>
      <category>techblogs</category>
    </item>
    <item>
      <title>{ my learnings through Error message “error:0308010C:digital envelope routines::unsupported” }</title>
      <dc:creator>Shreyansi Shrestha</dc:creator>
      <pubDate>Thu, 19 Dec 2024 04:15:15 +0000</pubDate>
      <link>https://forem.com/shreyansii/my-learnings-through-error-message-error0308010cdigital-envelope-routinesunsupported-331n</link>
      <guid>https://forem.com/shreyansii/my-learnings-through-error-message-error0308010cdigital-envelope-routinesunsupported-331n</guid>
      <description>&lt;p&gt;While I was working on my full-stack application, I came across this cryptographic error and when I searched for it on StackOverflow and ChatGPT, I got to know it arised due to changes in Node.js's handling of OpenSSL, affecting cryptographic operations,i.e., my application was attempting to use cryptographic algorithms or features that are no longer supported in the current OpenSSL version bundled with Node.js. So, the error actually came from the dependency I downloaded relying on an obsolete version of SSL.&lt;/p&gt;

&lt;p&gt;Thereupon, to fix this error :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Initially, I tried deleting my node_modules folder (from the frontend &lt;br&gt;
workspace/folder)  and re-running npm install in order to reinstall &lt;br&gt;
the dependencies. However, this did not solve the issue.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, I now understood that I should be switching the deprecated &lt;br&gt;
algorithm to legacy mode in order to solve the compatibility issues. &lt;br&gt;
And, while surfing regarding the deprecated algorithms, it got me &lt;br&gt;
reminded of the SHA-1 in PGP (Pretty Good Privacy) I learnt in the &lt;br&gt;
prior semester in college, in Computer Networks. SHA-1 is a hashing &lt;br&gt;
algorithm which has become a deprecated algorithm because of the &lt;br&gt;
security issues.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9bgjow331r7ujrad1s7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs9bgjow331r7ujrad1s7.png" alt="Image description" width="800" height="430"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;And continuing with the topic, since my app was a non-critical application which required some backward compatibility too, I decided to continue with using the --openssl-legacy-provider flag for a temporary workaround, as this would help me learn more about the possible errors that might occur, know more about root causes and how to solve it, along with other various terms that I might possibly encounter during the process.&lt;/p&gt;

&lt;p&gt;The --openssl-legacy-provider enables the use of legacy algorithms by instructing Node.js to utilize OpenSSL's legacy provider, thereby restoring support for such cryptographic functions.&lt;/p&gt;

&lt;p&gt;So, in the terminal, i started with :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm update
npm audit fix — force 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, on the package.json file, I made the following changes :&lt;/p&gt;

&lt;p&gt;BEFORE :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AFTER :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "start": "react-scripts --openssl-legacy-provider start",
    "build": "react-scripts --openssl-legacy-provider build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, this finally solved the issue and I loved how I progressed learning about different things just by trying to resolve this issue myself, learnings about how npm functions in detail, how versions are managed, about the deprecated and legacy algorithms, etc.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>react</category>
      <category>javascript</category>
      <category>techblogs</category>
    </item>
  </channel>
</rss>
