So if you need to generate passwords easy you don't have to reinvent the wheel, you can use functionality that the Mempership functionality from ASP.NET already has. On the Membership class in System.Web.Security namespace is a static method for generating passwords. You can specify a length and how many non alphanumeric characters it should contain.
Of course its not exotic in anyway and you can not control the set of characters used (apart from how many should be non alphanumeric) and it does not generate pronounceable passwords.
string password = Membership.GeneratePassword(7, 1);
The above code will generate a string with seven random characters. Its worth taking note of the second parameter. It specifies the minimum number of non-alphanumerical characters so the generated password can contain more than one in the above case.
If you need to generate pronounceable passwords I would recommend you take a look at the C implementation available here: http://www.multicians.org/thvv/tvvtools.html#gpw it covers the theory behind using trigraphs and furthermore shows implementation of how to extract trigraphs from a dictionary and how to use this to generate the actual passwords.
But to keep it short, if you just need a random set of chars. Use the features already in the framework instead of rolling your own! The lines saved makes fewer lines that could contain that tricky bug you are hunting a few months from now.
So if you need to generate passwords easy you don't have to reinvent the wheel, you can use functionality that the Mempership functionality from ASP.NET already has. On the Membership class in System.Web.Security namespace is a static method for generating passwords. You can specify a length and how many non alphanumeric characters it should contain.
Of course its not exotic in anyway and you can not control the set of characters used (apart from how many should be non alphanumeric) and it does not generate pronounceable passwords.
string password = Membership.GeneratePassword(7, 1);
The above code will generate a string with seven random characters. Its worth taking note of the second parameter. It specifies the minimum number of non-alphanumerical characters so the generated password can contain more than one in the above case.
If you need to generate pronounceable passwords I would recommend you take a look at the C implementation available here: http://www.multicians.org/thvv/tvvtools.html#gpw it covers the theory behind using trigraphs and furthermore shows implementation of how to extract trigraphs from a dictionary and how to use this to generate the actual passwords.
But to keep it short, if you just need a random set of chars. Use the features already in the framework instead of rolling your own! The lines saved makes fewer lines that could contain that tricky bug you are hunting a few months from now.
So if you need to generate passwords easy you don't have to reinvent the wheel, you can use functionality that the Mempership functionality from ASP.NET already has. On the Membership class in System.Web.Security namespace is a static method for generating passwords. You can specify a length and how many non alphanumeric characters it should contain.
Of course its not exotic in anyway and you can not control the set of characters used (apart from how many should be non alphanumeric) and it does not generate pronounceable passwords.
string password = Membership.GeneratePassword(7, 1);
The above code will generate a string with seven random characters. Its worth taking note of the second parameter. It specifies the minimum number of non-alphanumerical characters so the generated password can contain more than one in the above case.
If you need to generate pronounceable passwords I would recommend you take a look at the C implementation available here: http://www.multicians.org/thvv/tvvtools.html#gpw it covers the theory behind using trigraphs and furthermore shows implementation of how to extract trigraphs from a dictionary and how to use this to generate the actual passwords.
But to keep it short, if you just need a random set of chars. Use the features already in the framework instead of rolling your own! The lines saved makes fewer lines that could contain that tricky bug you are hunting a few months from now.
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
WebRequest req = HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
WebResponse response = req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
Actually the structure with the Create method on HttpWebRequest that returns a WebRequest object is more or less the Factory method design pattern implemented. Besides HttpWebRequest we have FtpWebRequest and a few more as concrete WebRequest that can be created the same way.
FileInfo fileToUpload = new FileInfo("c:\\path\\to\\file.ext");
WebRequest req = FtpWebRequest.Create("ftp://domain.dk/folder/" + fileToUpload.Name);
req.Credentials = new NetworkCredential("username", "password");
req.Method = WebRequestMethods.Ftp.UploadFile;
Stream s = req.GetRequestStream();
//Copy data from file to requeststream
const int bufferlen = 2048;
byte[] buffer = new byte[bufferlen];
int count = 0;
int readbytes;
FileStream uploadFilestream = File.OpenRead(fileToUpload.FullName);
do{
readbytes = uploadFilestream.Read(buffer, 0, bufferlen);
s.Write(buffer, 0, readbytes);
count += readbytes;
}while (readbytes != 0);
uploadFilestream.Close();
uploadFilestream.Dispose();
s.Close();
//Send the file by asking for the response
WebResponse response = req.GetResponse();
WebClient client = new WebClient();
Client.DownloadFile("http://www.domain.com/file.ext", @"c:\testfil.html");
WebClient client = new WebClient();
byte[] data = Client.DownloadFile("http://www.domain.com/file.ext");
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.UploadFile("ftp://domain.com/path/to.file", "c:\\path\\to\\file.ext");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
WebRequest req = HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
WebResponse response = req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
Actually the structure with the Create method on HttpWebRequest that returns a WebRequest object is more or less the Factory method design pattern implemented. Besides HttpWebRequest we have FtpWebRequest and a few more as concrete WebRequest that can be created the same way.
FileInfo fileToUpload = new FileInfo("c:\\path\\to\\file.ext");
WebRequest req = FtpWebRequest.Create("ftp://domain.dk/folder/" + fileToUpload.Name);
req.Credentials = new NetworkCredential("username", "password");
req.Method = WebRequestMethods.Ftp.UploadFile;
Stream s = req.GetRequestStream();
//Copy data from file to requeststream
const int bufferlen = 2048;
byte[] buffer = new byte[bufferlen];
int count = 0;
int readbytes;
FileStream uploadFilestream = File.OpenRead(fileToUpload.FullName);
do{
readbytes = uploadFilestream.Read(buffer, 0, bufferlen);
s.Write(buffer, 0, readbytes);
count += readbytes;
}while (readbytes != 0);
uploadFilestream.Close();
uploadFilestream.Dispose();
s.Close();
//Send the file by asking for the response
WebResponse response = req.GetResponse();
WebClient client = new WebClient();
Client.DownloadFile("http://www.domain.com/file.ext", @"c:\testfil.html");
WebClient client = new WebClient();
byte[] data = Client.DownloadFile("http://www.domain.com/file.ext");
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.UploadFile("ftp://domain.com/path/to.file", "c:\\path\\to\\file.ext");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
WebRequest req = HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
WebResponse response = req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
Actually the structure with the Create method on HttpWebRequest that returns a WebRequest object is more or less the Factory method design pattern implemented. Besides HttpWebRequest we have FtpWebRequest and a few more as concrete WebRequest that can be created the same way.
FileInfo fileToUpload = new FileInfo("c:\\path\\to\\file.ext");
WebRequest req = FtpWebRequest.Create("ftp://domain.dk/folder/" + fileToUpload.Name);
req.Credentials = new NetworkCredential("username", "password");
req.Method = WebRequestMethods.Ftp.UploadFile;
Stream s = req.GetRequestStream();
//Copy data from file to requeststream
const int bufferlen = 2048;
byte[] buffer = new byte[bufferlen];
int count = 0;
int readbytes;
FileStream uploadFilestream = File.OpenRead(fileToUpload.FullName);
do{
readbytes = uploadFilestream.Read(buffer, 0, bufferlen);
s.Write(buffer, 0, readbytes);
count += readbytes;
}while (readbytes != 0);
uploadFilestream.Close();
uploadFilestream.Dispose();
s.Close();
//Send the file by asking for the response
WebResponse response = req.GetResponse();
WebClient client = new WebClient();
Client.DownloadFile("http://www.domain.com/file.ext", @"c:\testfil.html");
WebClient client = new WebClient();
byte[] data = Client.DownloadFile("http://www.domain.com/file.ext");
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.UploadFile("ftp://domain.com/path/to.file", "c:\\path\\to\\file.ext");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
WebRequest req = HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
WebResponse response = req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
Actually the structure with the Create method on HttpWebRequest that returns a WebRequest object is more or less the Factory method design pattern implemented. Besides HttpWebRequest we have FtpWebRequest and a few more as concrete WebRequest that can be created the same way.
FileInfo fileToUpload = new FileInfo("c:\\path\\to\\file.ext");
WebRequest req = FtpWebRequest.Create("ftp://domain.dk/folder/" + fileToUpload.Name);
req.Credentials = new NetworkCredential("username", "password");
req.Method = WebRequestMethods.Ftp.UploadFile;
Stream s = req.GetRequestStream();
//Copy data from file to requeststream
const int bufferlen = 2048;
byte[] buffer = new byte[bufferlen];
int count = 0;
int readbytes;
FileStream uploadFilestream = File.OpenRead(fileToUpload.FullName);
do{
readbytes = uploadFilestream.Read(buffer, 0, bufferlen);
s.Write(buffer, 0, readbytes);
count += readbytes;
}while (readbytes != 0);
uploadFilestream.Close();
uploadFilestream.Dispose();
s.Close();
//Send the file by asking for the response
WebResponse response = req.GetResponse();
WebClient client = new WebClient();
Client.DownloadFile("http://www.domain.com/file.ext", @"c:\testfil.html");
WebClient client = new WebClient();
byte[] data = Client.DownloadFile("http://www.domain.com/file.ext");
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.UploadFile("ftp://domain.com/path/to.file", "c:\\path\\to\\file.ext");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
WebRequest req = HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
WebResponse response = req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
Actually the structure with the Create method on HttpWebRequest that returns a WebRequest object is more or less the Factory method design pattern implemented. Besides HttpWebRequest we have FtpWebRequest and a few more as concrete WebRequest that can be created the same way.
FileInfo fileToUpload = new FileInfo("c:\\path\\to\\file.ext");
WebRequest req = FtpWebRequest.Create("ftp://domain.dk/folder/" + fileToUpload.Name);
req.Credentials = new NetworkCredential("username", "password");
req.Method = WebRequestMethods.Ftp.UploadFile;
Stream s = req.GetRequestStream();
//Copy data from file to requeststream
const int bufferlen = 2048;
byte[] buffer = new byte[bufferlen];
int count = 0;
int readbytes;
FileStream uploadFilestream = File.OpenRead(fileToUpload.FullName);
do{
readbytes = uploadFilestream.Read(buffer, 0, bufferlen);
s.Write(buffer, 0, readbytes);
count += readbytes;
}while (readbytes != 0);
uploadFilestream.Close();
uploadFilestream.Dispose();
s.Close();
//Send the file by asking for the response
WebResponse response = req.GetResponse();
WebClient client = new WebClient();
Client.DownloadFile("http://www.domain.com/file.ext", @"c:\testfil.html");
WebClient client = new WebClient();
byte[] data = Client.DownloadFile("http://www.domain.com/file.ext");
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.UploadFile("ftp://domain.com/path/to.file", "c:\\path\\to\\file.ext");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
WebRequest req = HttpWebRequest.Create("http://www.domain.com/file.ext");
req.Method = WebRequestMethods.Http.Get;
WebResponse response = req.GetResponse();
long length = response.ContentLength;
Stream s = response.GetResponseStream();
//Process stream using the length
Actually the structure with the Create method on HttpWebRequest that returns a WebRequest object is more or less the Factory method design pattern implemented. Besides HttpWebRequest we have FtpWebRequest and a few more as concrete WebRequest that can be created the same way.
FileInfo fileToUpload = new FileInfo("c:\\path\\to\\file.ext");
WebRequest req = FtpWebRequest.Create("ftp://domain.dk/folder/" + fileToUpload.Name);
req.Credentials = new NetworkCredential("username", "password");
req.Method = WebRequestMethods.Ftp.UploadFile;
Stream s = req.GetRequestStream();
//Copy data from file to requeststream
const int bufferlen = 2048;
byte[] buffer = new byte[bufferlen];
int count = 0;
int readbytes;
FileStream uploadFilestream = File.OpenRead(fileToUpload.FullName);
do{
readbytes = uploadFilestream.Read(buffer, 0, bufferlen);
s.Write(buffer, 0, readbytes);
count += readbytes;
}while (readbytes != 0);
uploadFilestream.Close();
uploadFilestream.Dispose();
s.Close();
//Send the file by asking for the response
WebResponse response = req.GetResponse();
WebClient client = new WebClient();
Client.DownloadFile("http://www.domain.com/file.ext", @"c:\testfil.html");
WebClient client = new WebClient();
byte[] data = Client.DownloadFile("http://www.domain.com/file.ext");
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("username", "password");
client.UploadFile("ftp://domain.com/path/to.file", "c:\\path\\to\\file.ext");