How to get a count of the characters allowed for use in url passwords in any language.

The documentation states CharacterSet and CharacterSet.urlPasswordAllowed are each a set, assuming a Swift set. As such I should be allowed to append ".count".


"However, I get a compiler error: "Value of type 'CharacterSet' has no member 'count'".


Inserting this into my code:

for char in CharacterSet.urlPasswordAllowed { print(char) }


compiler error:

Type 'CharacterSet' does not conform to protocol 'Sequence'


Which indicates CharacterSet isnota Swift set.


Inserting this into my code:

print(CharacterSet.urlPasswordAllowed)


prints output to debugging area:

<CFCharacterSet Bitmap>



How then can I get a count of the characters allowed for use in url passwords in any language?

I assume Apple has this set defined for every language that has a system font defined.

Answered by Claude31 in 405890022

It is a struct, not a Swift Set.


May read this

h ttps://medium.com/livefront/understanding-swifts-characterset-5a7a89a32b54

Accepted Answer

It is a struct, not a Swift Set.


May read this

h ttps://medium.com/livefront/understanding-swifts-characterset-5a7a89a32b54

Thanks for the excellent info. You are a good man for helping us!


It is much more difficult than I imagined and would more than triple the code of my little app if I implemented their "scan of all unicode code units". |-) I'll just keep my less expensive method of generating chars.


Thanks again.

Wish you good continuation.


And don't forget to close the thread …

What are you trying to do here? I understand your low-level goal, but why do you need this count? It’s a relatively unusual requirement. Moreover, this comment:

I assume Apple has this set defined for every language that has a system font defined.

suggests a serious misunderstanding of what the

urlPasswordAllowed
represents. It’s not language or font dependent, but rather defined by Internet standards (specifically, RFC 3986).

If you can explain more about your high-level goal, I’m hoping that I can steer you in the right direction.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Sorry for not replying sooner, but I just discovered "Content" on this forum and how to use it. I'm a newbie.


My simple app uses arc4random to generate password characters. I currently feed it a range of several thousand (Int) to ensure any languages, e.g., Chinese which I hear has thousands of characters, have all possible characters. This is inefficient, although effective. I thought if I had the fixed range, or count of characters allowed in passwords, I could reset to that range for that language.

I had no knowledge of the RFC's relation. I'll look into it. Thanks.

In practice, over-ranging arc4random might just improve its unbreakablity with that extra degree of proprietary info (the range). It is wasteful but not so slow as to notice or annoy.


btw: newbie is not in the spell checkers dictionary. Curious.


Thanks for your help.

Generating random passwords that contain non-ASCII characters is very tricky. The problem is that many non-ASCII characters are not typable, that is, there’s simply no way for the user to enter that value.

Indeed, this is even true for some ASCII characters (like U+007F DELETE) but you can special case those.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
How to get a count of the characters allowed for use in url passwords in any language.
 
 
Q