foens / hpop

OpenPOP.NET code repository
http://hpop.sourceforge.net/
202 stars 115 forks source link

Able to have European characters as password like "é" #30

Open qqterry opened 9 years ago

qqterry commented 9 years ago

Hi there,

would it be easy to add capability like authentication with european characeter like "é", because currently if I have set up a email account that have password with "é" in it, when it comes to the Pop3Client.Authenticate() method it just give InvalidLoginException.

foens commented 9 years ago

I'm not sure how other POP3 clients handle this situation. Have you tried to authenticate using a non-plaintext method? You can do this by giving a AuthenticationMethod to the Authenticate method.

qqterry commented 9 years ago

As for other methods of Authentication will require the server to enable those authentication methods on the server which can cause more work for the user, that is something which i am trying to avoid.

I know usually the email server only take alphanumeric as password, but would it be very hard to add it?

foens commented 9 years ago

I do not know. Do you know how to implement it? Are there any RFC that specifies how to do it?

jstedfast commented 8 years ago

Figured I'd chime in here having a fair bit of experience in this area...

Unfortunately, the POP3 protocol does not specify a charset encoding for user names or passwords when it comes to the USER and PASS commands. All you can really do is pick an encoding and hope that the server is using the same one.

I would expect that most servers likely use UTF-8 these days and not a locale-specific encoding, but I wouldn't be surprised if some still do.

The same goes for SASL mechanisms such as PLAIN and LOGIN.

That said, presumably OpenPOP already uses Encoding.UTF8.GetBytes() when writing to the socket, so if it doesn't work, then that means the server is not using UTF-8 which means the only way to implement this would be to offer a ServerEncoding property that allows the user to specify what charset encoding the server is using for user names and passwords?

jstedfast commented 8 years ago

I took a look at the code and it might be as simple as changing the following line:

https://github.com/foens/hpop/blob/master/OpenPop/Pop3/Pop3Client.cs#L907

From using Encoding.ASCII to Encoding.UTF8.

foens commented 8 years ago

@jstedfast Really. I thought the protocol was strictly ASCII based?

jstedfast commented 8 years ago

@foens specifications and practice often do not correspond in the world of email :(

The reality is that most server software is written using C-strings (byte arrays), and they do not generally enforce ASCII-only passwords, so as long as the binary blob password token matches the binary blob in the passwords database, things work.

This means that the password stored in the database is typically in whatever charset the system was using when the user created his/her password (assuming it wasn't canonicalized into UTF-8).

Most Linux and other UNIX servers these days default to the UTF-8 charset for all locales, so those will generally store user names and passwords in UTF-8, which means that if you use Encoding.UTF8.GetBytes(), things will usually magically just work.

If that doesn't work, then most likely the server is using the region's locale charset and God help us if that's the case because there is no way the client could figure it out, which is why I said the only solution if this is the case is to have a ServerEncoding property.

Anyway, I hope that helps explain things a bit more...