選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

isInsecureRoomName.js 812B

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