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

Implement secure password comparison in AuthLogin class #19

Open
coderabbitai bot opened this issue Jul 24, 2024 · 1 comment
Open

Implement secure password comparison in AuthLogin class #19

coderabbitai bot opened this issue Jul 24, 2024 · 1 comment
Assignees

Comments

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 24, 2024

The current implementation of the AuthLogin class in libs/web/src/services/AuthLogin.ts uses plain text password comparison. For enhanced security, it is recommended to use a secure password comparison method such as bcrypt.

Suggested Changes

  1. Install bcrypt library.
  2. Modify the login method in the AuthLogin class to use bcrypt.compare for password comparison.

Example:

import bcrypt from 'bcrypt';

export class AuthLogin {
  private sequelize: Sequelize;

  constructor(sequelize: Sequelize) {
    this.sequelize = sequelize;
  }

  async login(
    username: string,
    password: string
  ): Promise<Omit<UserAttributes, "id"> | null> {
    log.debug("AuthLogin.login");
    log.debug(`username: ${username}`);
    const user = await User.findOne({
      where: {
        username,
      },
    });

    if (!user || !(await bcrypt.compare(password, user.password))) {
      return null;
    }

    return {
      username: user.username,
      password: user.password,
    };
  }
}

References

This change will ensure that passwords are compared securely, enhancing the overall security of the authentication process.

Requested by: @drazisil
Related PR: #17 (comment)

@drazisil
Copy link
Contributor

TODO:

  • create ability to insert encrypted logins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant