bcryptjs#compare TypeScript Examples

The following examples show how to use bcryptjs#compare. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: login.ts    From TypeScript-Login-Register with MIT License 5 votes vote down vote up
alt.onClient(
  "client::lr:loginAccount",
  async (player: alt.Player, data: ILoginAccountData) => {
    try {
      data.socialId = player.socialId;
      const loginConnection = getConnection("lr");
      const result = await loginConnection
        .createQueryBuilder(Account, "account")
        .leftJoinAndSelect("account.validation", "validation")
        .where("account.username = :username", { username: data.username })
        .getOne();
      if (!result) {
        let err: IErrorMessage = {
          location: "login",
          param: "username",
          msg: "The given username does not exist",
        };
        return alt.emitClient(player, "server::lr:showLoginError", err);
      }

      let passwordResult: boolean = await compare(
        data.password,
        result.password
      );

      if (!passwordResult) {
        let err: IErrorMessage = {
          location: "login",
          param: "password",
          msg: "The given password is incorrect",
        };
        return alt.emitClient(player, "server::lr:showLoginError", err);
      }

      if (data.socialClub != result.validation.scNickname) {
        let err: IErrorMessage = {
          location: "login",
          param: "scNickname",
          msg:
            "Your socialclub name diffes from the one, you registred with, please use your old account to login",
        };
        return alt.emitClient(player, "server::lr:showLoginError", err);
      }

      if (data.socialId != result.validation.socialId) {
        let err: IErrorMessage = {
          location: "login",
          param: "socialId",
          msg:
            "Your socialclub id diffes from the one, you registred with, please use your old account to login",
        };
        return alt.emitClient(player, "server::lr:showLoginError", err);
      }

      const loginData: ILoginAccountData = {
        socialClub: result.validation.scNickname,
        username: result.username,
        discordUserID: result.validation.discordUserID,
      };

      player.setSyncedMeta("userData", loginData);

      alt.emitClient(player, "client:lr:loginSuccessfull");
    } catch (error) {
      alt.log(error);
      let err: IErrorMessage = {
        location: "server",
        param: "",
        msg: "Internal server error, please try again later",
      };
      return alt.emitClient(player, "server::lr:showLoginError", err);
    }
  }
);
Example #2
Source File: BCryptHashProvider.ts    From gobarber-api with MIT License 5 votes vote down vote up
public async comapreHash(payload: string, hashed: string): Promise<boolean> {
    return compare(payload, hashed);
  }
Example #3
Source File: BCryptHashProvider.ts    From hotseat-api with MIT License 5 votes vote down vote up
public async compareHash(payload: string, hashed: string): Promise<boolean> {
    const payloadMatch = await compare(payload, hashed);

    return payloadMatch;
  }
Example #4
Source File: status.ts    From nodestatus with MIT License 5 votes vote down vote up
export async function authServer(username: string, password: string): Promise<boolean> {
  const res = await handleRequest(readServerPassword(username));
  if (res.code || !res.data) return false;
  return compare(password, res.data);
}
Example #5
Source File: user.ts    From ts-oauth2-server with MIT License 5 votes vote down vote up
async verify(password: string) {
    if (!(await compare(password, this.passwordHash))) {
      throw new Error("invalid password");
    }
  }
Example #6
Source File: BCryptHashProvider.ts    From gobarber-project with MIT License 5 votes vote down vote up
public async compareHash(payload: string, hashed: string): Promise<boolean> {
    return compare(payload, hashed);
  }
Example #7
Source File: BCryptHashProvider.ts    From GoBarber with MIT License 5 votes vote down vote up
public async compareHash(payload: string, hashed: string): Promise<boolean> {
    return compare(payload, hashed);
  }
Example #8
Source File: user.entity.ts    From postgres-nest-react-typescript-boilerplate with GNU General Public License v3.0 5 votes vote down vote up
comparePassword = async (attempt: string) => {
    return await compare(attempt, this.password);
  };
Example #9
Source File: matchPassword.ts    From tezos-academy with MIT License 5 votes vote down vote up
matchPassword: MatchPassword = async (proposedPassword, hashedPassword) => {
  const isMatch: boolean = await compare(proposedPassword, hashedPassword)
  if (!isMatch) throw new ResponseError(401, 'Wrong username or password')
}
Example #10
Source File: User.ts    From typescript-clean-architecture with MIT License 5 votes vote down vote up
public async comparePassword(password: string): Promise<boolean> {
    return compare(password, this.password);
  }