Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you tell if unicode letters are sequential in Java?

The general requirment is that I need to implement a method for passwords that does not accept three sequential letters or numbers - so no 'abc123' passwords.

I need a way to see if three letters are sequentially after each other - obviously with any single language this is fairly simple, but a general purpose code for every unicode language seems to escape me.

I assume first I would need a method of figuring out if the three characters are in the same language, and then figure out if they are sequentially after each other. In unicode, there are also languages that are not ordered in any particular way - so there would need to be a way to tell if we were in a language that had order or not.

Is this as complicated as I'm imagining, or are there Java libraries / inherent patterns within unicode that allow something like this?

If I were to reduce the requirements, so that I would just numerically compare the unicode numbers to each other, are there any real world scenarios that I would run into trouble with? i.e. is it likely that someone would choose a password that contained the two ending letters of one language and the first of the next, in a valid way?

like image 878
RankWeis Avatar asked Oct 20 '22 20:10

RankWeis


1 Answers

If I were you I would get the unicode position of the char and check if the next character has position of the first + 1 - This should work for all languages since Unicode code points should be sorted.

like image 132
Florian Loch Avatar answered Oct 23 '22 22:10

Florian Loch