I'm using openpop to connect to gmail pop server.
This is the code (very simple)
using (var client = new Pop3Client())
{
var username = mailProperties.UserId;
client.Connect(mailProperties.Server, mailProperties.Port, mailProperties.UseSsl);
client.Authenticate(username, mailProperties.Password);
}
Most of the time it works. But if the password contains "./", the authentication fails and I have an Invalid login exception.
Do I have to encode the password or something? I tried Uri.EscapeDataString but the result is the same.
I verified the password and it's the good one ;)
I forgot to activate the pop access in my gmail option for this account.
The problem is now solved.
Related
I'm using SoftEther APIs to connect to a VPS and then try to build a VPN on that .
I can successfully connect to server using IP and Port, then at Authentication step I get "Access denied" and no more details.
The authentication step is using Password and HubName.
I've read the APIs codes deeply and I realized it using SHA0 algorithm to encrypt password and take a random arrays of bytes from server and use that as salt in encrypt method .
So I've changed the encryption method at SoftEther Application to AES128 , AES256 and some others but the result has not been changed at all.
I also tried to send password as an ASCII but none of them worked.
The exact API code without change:
using (var softEther = new SoftEther(ip, port))
{
// the connection step that would pass successfully :
var connectResult = softEther.Connect();
if (!connectResult.Valid())
{
Console.WriteLine(connectResult.Error);
return;
}
// the Authentication step that got problem :
var authResult = softEther.Authenticate(pw, hubName);
if (!authResult.Valid())
{
Console.WriteLine(authResult.Error);
return;
}
// the code stops and don't get here :
var user = softEther.HubApi.GetUser(hubName, userName);
Console.WriteLine(user.Valid() ? "Success" :
user.Error.ToString());
}
And this is the authResult I get
Well since you are working on server side of SoftEther i would recommend you to use VPNCMD for managing or retrieving info from SoftEther server.
VPNCMD Virtual Hub commands:
https://www.softether.org/4-docs/1-manual/6._Command_Line_Management_Utility_Manual/6.4_VPN_Server_%2F%2F_VPN_Bridge_Management_Command_Reference_(For_Virtual_Hub)
For example enter the following in cmd/terminal:
vpncmd /server {serverIP} /PASSWORD:{server password}
/adminhub:{server HUB Name} /CMD UserCreate {username}
/GROUP:{groupname} /REALNAME:{user fullname} /NOTE:{anything}
Requirements:
Download and install SoftEther server manager for your machine OS(ie from where you want to control remote server)
You can also execute VPN Client functions from VPNCMD:https://www.softether.org/4-docs/1-manual/6._Command_Line_Management_Utility_Manual/6.5_VPN_Client_Management_Command_Reference
I create a method for send Email like:
public async Task SendEmailCC(string body, string subject, List<string> mainRecievers, List<string> receivers)
{
SmtpClient client = new SmtpClient("smtp-mail.outlook.com")
{
UseDefaultCredentials = true,
Port = 587,
EnableSsl = true,
DeliveryMethod = SmtpDeliveryMethod.Network,
Credentials = new NetworkCredential("Test#gmail.com", "MyMailPassword")
};
MailMessage mailMessage = new MailMessage { From = new MailAddress("job#test.org") };
foreach (var reciever in mainRecievers)
{
mailMessage.To.Add(reciever);
}
foreach (var item in receivers)
{
mailMessage.CC.Add(item);
}
mailMessage.Body = body;
mailMessage.IsBodyHtml = true;
mailMessage.Subject = subject;
await client.SendMailAsync(mailMessage);
}
For test, I send an email to my self, but I didn't get Email. how can I find my problem?
My exception is connection auth.
Mail server was google and I used of OutLookSmtp,To this section of my code I have that and I changed. like:
SmtpClient client = new SmtpClient("smtp-mail.outlook.com")
And changed:
SmtpClient client = new SmtpClient("smtp.gmail.com")
After that I get this exception:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required", than the error might occur due to following cases.
For this issue I try this:
case 1: when the password is wrong
case 2: when you try to login from some App
case 3: when you try to login from the domain other than your time zone/domain/computer (This is the case in most of scenarios when sending mail from code)
There is a solution for each
solution for case 1: Enter the correct password.
solution 1 for case 2: go to security settings at the followig link https://www.google.com/settings/security/lesssecureapps and enable less secure apps . So that you will be able to login from all apps.
solution 2 for case 2:(see https://stackoverflow.com/a/9572958/52277) enable two-factor authentication (aka two-step verification) , and then generate an application-specific password. Use that newly generated password to authenticate via SMTP.
solution 1 for case 3: (This might be helpful) you need to review the activity. but reviewing the activity will not be helpful due to latest security standards the link will not be useful. So try the below case.
solution 2 for case 3: If you have hosted your code somewhere on production server and if you have access to the production server, than take remote desktop connection to the production server and try to login once from the browser of the production server. This will add excpetioon for login to google and you will be allowed to login from code.
But what if you don't have access to the production server. try the solution 3
solution 3 for case 3: You have to enable login from other timezone / ip for your google account.
to do this follow the link https://g.co/allowaccess and allow access by clicking the continue button.
And that's it. Here you go. Now you will be able to login from any of the computer and by any means of app to your google account
If you try to visit ftp.yealink.com you will get a MessageBox saying:
The Server ftp://ftp.yealink.com:21 requires a username and a password.
How do I receive the above text using C#?
Can it be done through the WebClient class?
Edit: I think some of you misunderstood me. I am not looking to connect to the FTP server, or handle the exception. All I want is a string with the value: "The Server ftp://ftp.yealink.com:21 requires a username and a password."
If you use the WebClient class to connect to an ftp site, you need to create a NetworkCredentials instance to store your login info (username, password):
var client = new WebClient { Credentials = new NetworkCredential("username", "password") };
try
{
var data = client.DownloadData(<some uri to a file path on the ftp site>);
...
}
catch (WebException e)
{
// handle any exceptions
}
More info can be found here: http://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest.aspx
EDIT:
You clarified that you're looking for the popup text shown in your browser when clicking on the ftp link. The text string of "The Server ... requires a username and a password" is generated by your browser (Chrome). Firefox pops up a message box stating "Enter username and password for ..." and Safari says "Enter your name and password for the server ..." The text you're trying to capture isn't output by the ftp server.
When connecting you will receive a WebException with StatusCode 421. This means Not authorized. Handle the exception and retry.
Given the comments you place I think you are looking for the WelcomeMessage and BannerMessage from the response.
I am trying to redirect an http request with digest MD5 header information to an active directory to validate the credentials.
I do have the information given by the http header like nonce and username. My problem now is that I have no link to put this information into a PrincipalContext object.
I obviously can't use PrincipalContext.ValidateCredentials(username, password) cause it requires the password in plain text.
The only validation that I am able to use is UserPrincipal user = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);, but this does not include the password.
I do have a HttpListenerContext object. But the user variable is null.
After I told my server to user AuthenticationSchemes.IntegratedWindowsAuthentication he automaticaly deliveres a WindowsPrincipal, which provides information from the AD.
Tim once you get the information you can do something like this to check if is Valid or not If I am understanding what you want to test properly then try something like this
if you are running this via code or a service you should have no issues with the password in regards to being exposed ..if you are concerned about that then you need to write something that will decrypt the MD5 Header Information where the pass word is.
using(PrincipalContext prContext= new PrincipalContext(ContextType.Domain, "Your Domain"))
{
bool isValid = prContext.ValidateCredentials("Username", "Password");
}
I am using this to download html content from a site published on IIS:
using (var client = new WebClient())
{
client.Credentials = CredentialCache.DefaultCredentials;
string html = client.DownloadString("http://site.com");
}
But when the IIS is set to Basic Authentication this doesn't works. The user already type user and password on the IIS dialog box.
There is a way to make this work without pass a user and password again?
I suspect that basic authentication is going to need the password, so I suspect you'll need a new System.Net.NetworkCredential("your-username","your-password"). The default credential would work with integrated auth, but not (AFAIK) basic. So in answer to:
There is a way to make this work without pass a user and password again?
No, I don't think so.
Searching more, I found this:
HttpApplication context = (HttpApplication)HttpContext.Current.ApplicationInstance;
string authHeader = context.Request.Headers["Authorization"];
string userNameAndPassword = Encoding.Default.GetString(
Convert.FromBase64String(authHeader.Substring(6)));
string[] parts = userNameAndPassword.Split(':');
Response.Write(userNameAndPassword);
We can get user and password when the IIS is set do basic authentication!
I use the following code for the NTLM authentication with default credentials
webClient.Proxy = WebRequest.GetSystemWebProxy();
webClient.Proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
One day I researched the problem and found this working. However, with .Net 4.0 my Visual Studio says GetSystemWebProxy is currently deprecated.