c# authenticate phpbb forum user in application - c#

I would like to have a simple authentication on my software. I know I will need to use HttpWebRequest and send the post data/ headers, but I have not been able to figure it out.... does anyone have any examples?

Sorry about the lack of information. I have been able to resolve the issue by creating a custom phpbb forum login php page that takes username / password parameters and I send the request from my software application to this php I've created and wait for the response and see if the php was able to validate the login.

There is a better way, Unfortunately I lost my Phpbb application, but it was based on the code provided Here
It creates a header for phpbb, and stores the cookies, allowing you to do alot with it.

Related

login website like(FB, TWITTER ) and crawl data with c#?

I am creating a console application in c#(visual studio).
but i don't know where to start.
1st i want to login(phantomjs or selenium)>>then go to a (specified)website URL and extract html?
i want to know how to save login information in my web request.
thank you.
Long story short, it's not easy to do that just with web request because each site has its own way of managing cookies and security.
It's easier if you use a web browser control to login first. From there, the browser can obtain a valid cookie and you can start crawl data from there.
I've done a similar thing with Chegg website. For details, you can check out my repository https://github.com/hungqcao/chegg-solutions-saver
In your case, it can get a little complicated since FB, Twitter may have 2-factor authentication or something similar to that but the idea stays the same.
Let me know if you need help.

remote login identityserver3

I'm currently trying to connect my existing behaviour into IdentityServer3.
What I want to happen is when I post my login form back with username and password I can call my IdentityServer and authenticate in a single post request.
Are there existing helpers to support this?
Sorry If this has been asked I've been trawling around all day and haven't found anything.
So I have figured this out after loads of reading and playing, basically what I wanted was the resourceOwner flow which would allow me to authenticate without the browser. This isn't recommended as you loose the sso benefits. The other approach I looked at was to pass the post form values, username and password to the preauthenticate method on identity server. This seemed extremely hacky to me. I'll probably just use the normal flow if the client will allow it.

Send information to website server programmatically

I have very minimal experience with anything web related so apologies if this is a silly question.
I have a Wordpress site with a contact form which users can use to send me a message from the website. The user fills out the form, and it is converted into an email and sent to me.
I would like to have similar functionality from my c# desktop application.
In other words, I am looking for a way to either programmatically invoke the contact form on my website, or to send information to my website, which it will convert into an email and send it to me directly.
What general concepts should I be looking into?
The information typed into the web form is probably sent back to the web server using the HTTP POST method. Essentially the data entered into the web form is converted to name values pairs and sent to the WordPress app. More information on HTTP POST here: HTTP POST (Wikipedia)
To do the same from a C# app, you need to format the data to POST in a similar way and then look at using the HttpWebRequest class. This stackoverflow thread shows an example: HTTP request with POST. If you POST the information to the same URL the web page is using then the server should generate the email.
Just to note as well, if the WordPress app requires you to be logged in before submitting the information, then you'll need to include code to authenticate with the WordPress app within the C# app.
I hope this helps!

Remote logging into a website and fetching HTML source with WPFs WebBrowser class

I was trying to write a application which logs the user on a specific website after he inputs his account information and then present an specific site in the window which is only accessible after login.
I'm trying to do this with the WebBrowser Class from System.Windows.Controls.WebBrowser
However, even after searching other examples I can't seem to get past the login.
I used HttpFox to analyze the GET and POST data and found out that Cookies Sent are: _utma/b/c/z, clientid, csrftoken and sessionid and received sessionid.
Ok now I know that the _utma cookies are something about google analytics so I think I can ignore them? The csrftoken seems to have the same value always.
Can anyone give me some hints how to make the POST request in c# with the webbrowser class?
Help is very much appreciated, thanks! :)
update1: I already know the general methods I have to use but I'm having problems with the actual implementation. What should I include in the post request and how to get and save the sessionId,... things like that. I couldn't find any working example where someone is logging into some 3rd party website with the help of the WebBrowser class.
You could use WebClient.UploadData method to post data and to receive response from your script

Easiest way to get web page source code from pages that require logins -- C#

So I play an online game that's web based and I'd like to automate certain things with it using C#. Problem is that I can't simply use WebClient.DownloadData() because I need to be logged in to actually recieve the source. The other alternative was to use the built-in web browser control but that doesn't give me access to source code. Any suggestions?
I don't think NetworkCredentials will work in all cases. This only works with "Basic" or "Negotiate" authentication.
I've done this before with an internal website for some load testing, but sounds like you are trying to "game" the game. For that reason I won't go into details but the login to the site is probably being done in the form of an HTTP POST when you hit the login button.
You'd have to trap the POST request and replicate it in your code and make sure that your implementation maintains the session state as well, because if the game site is written well at all it will make sure that the current session has logged in before doing anything game related.
You can set the login credentials on the webclient using its Credentials property before calling DownloadData:
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
EDIT: As mjmarsh points out, this will only work for sites that use a challenge-response method of authentication as part of a single request (I'm so used to dealing with this at work, I hadn't considered the other types!). If the site uses forms authentication (or indeed any other form of authentication), this method will not work as the authentication is not part of a single request - multiple requests are needed that you will need to handle yourself.
Network credentials will not work as mjmarsh has already pointed out.
While web scraping we come across lot of pages where login is needed. One of the approaches I use is install fiddler and monitor the POST and GET packets while manually logging in the site. This allows you to find out how the browser emulates the login. Then you need to recreate the same process by Code.
For example, most web servers use cookies to assume the session is authenticated. So you can use the credentials to post UserName and Password on the web site and record the Cookie. This cookie can then be used to access any further details on the web site.
Please check following link to check out more about Advanced Web Scraping:
http://krishnan.co.in/blog/post/Web-Scraping-Yahoo-Mail.aspx
In this blog, you will find how to authenticate into Yahoo account and then read the page after authentication.

Categories