You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

isInsecureRoomName.ts 802B

12345678910111213141516171819202122232425262728293031323334
  1. import _ from 'lodash';
  2. import { NIL, parse as parseUUID } from 'uuid';
  3. import zxcvbn from 'zxcvbn';
  4. // The null UUID.
  5. const NIL_UUID = parseUUID(NIL);
  6. /**
  7. * Checks if the given string is a valid UUID or not.
  8. *
  9. * @param {string} str - The string to be checked.
  10. * @returns {boolean} - Whether the string is a valid UUID or not.
  11. */
  12. function isValidUUID(str: string) {
  13. let uuid;
  14. try {
  15. uuid = parseUUID(str);
  16. } catch (e) {
  17. return false;
  18. }
  19. return !_.isEqual(uuid, NIL_UUID);
  20. }
  21. /**
  22. * Returns true if the room name is considered a weak (insecure) one.
  23. *
  24. * @param {string} roomName - The room name.
  25. * @returns {boolean}
  26. */
  27. export default function isInsecureRoomName(roomName = ''): boolean {
  28. return !isValidUUID(roomName) && zxcvbn(roomName).score < 3;
  29. }