|
The Navigate method is blocking execution, until it completes or times out. An easy solution would be to put the webbrowser in it's own process and have it retrieve your data. You can start the process async, and terminate it if it doesn't return results within a specified time-range. Your main-application would then run the processes one after another, until it reaches the end of it's list.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
I have a question on password security. This is a requirement from a client, and I want to do it right.
Here's the requirements:
1) The code needs to use best practices and in a way that will perform well, scale well under load.
This isn't that big of a deal for me. I write pretty good code.
2) Here's what he asked for in his email
A) It must contain at least one vowel.
B) It cannot contain three consecutive vowels or three consecutive consonants.
C) It cannot contain two consecutive occurrences of the same letter, except for 'ee' or 'oo'.
My problems is that I think I could use RegEx for this, but I suck at RegEx. I'v always hated it becuase it seems so cryptic.
I don't have a problem working through the problem, or coding it - my problem is knowing where to go with this.
1) Is RegEx the answer?
2) Would you use another technique? Which one?
3) Anything in the .Net class libs that I can use?
Summaary is, I'm al little unsure how to move ahead on this, so any input I get would be great.
Thanks
|
|
|
|
|
|
I too think the client is talking through the wrong end of his body, but hey, you give the man what he wants, not what he needs.
Regex is the way to go, even if it causes you a little pain right now. Grab a copy of Expresso[^], the best free Regex tool on the planet*, and go to work.
You will need to clarify the requirements a bit - min/max length, allowed character set, etc, as well as the client's rules (ee and oo allowed but not tt seems a bit silly...)
Expresso allows you to build a regex incrementally, and it provides a tree-like view of what each little bit means, as well as testing as you go. Your regex may not fit on one line, but it'll probably fit in a tweet.
If you can get your client to provide you two lists - good and bad passwords - then you can run them as tests in Expresso.
If you get stuck along the way, post a question in the Regular Expressions forum[^].
* disclaimer: I have no connection to Expresso other than as a very satisfied user.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
I've used Expresso in the past and it is a great tool to have around.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
zephaneas wrote: little unsure how to move ahead on this
You should recommend to your client the criteria he has given you will not make the passwords strong at all and advise him that more strength is a good idea.
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
If a customer comes up with such ideas, try shortly to inform him on good practices. If he seems reluctant to realize the difference, give him what he insists to get.
And since new user registrations / password changes happen not so often, do not care for highest performance. Naive approaches are good enough.
Create character arrays for vowels and consonants, e.g. char[] vowels = "AaEeIiOoUu".ToCharArray(); , and condition A can be checked with the "IndexOfAny" method of string.
If the password is longer than 1 character (oh yes, "a" is a safe password for your customer...), check B and C by looping thru the characters of the password - you can access each character by the indexer, e.g. char c = password[0]; .
|
|
|
|
|
Those are really bad criteria, particularly as there's no length requirements in there which are the one thing that really makes a difference. "This is my password" is a much more secure one than "Ql5'J".
I don't think you can do C with a regex so you probably want to traverse the string yourself anyway, which makes A trivial and B rather easy.
|
|
|
|
|
He wants you to use best practices, but his own "requirements" violate best practices for passwords. I think you need to write a reply to the email, not code.
|
|
|
|
|
..and suggest that one should only use a GUID as an acceptable password, with the system sending you a new password to remember at least every two weeks
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
zephaneas wrote: A) It must contain at least one vowel.
So, a password of a is enough to satisfy the criteria.
As others have said, he needs to be educated as to best practices (e.g. use of symbols, minimum length, etc).
To answer the question though - I wouldn't use RegEx for something like this. You may get a working regular expression, but it will be tied to these requirements. If the criteria expands, you'll have to revisit the regex, and you may find that the solution is no longer valid. A fairly elegant solution would be to use the Visitor Pattern[^]. With this, you can add new rules without affecting the underlying logic, simply by adding new visitors.
|
|
|
|
|
I would like to accomplish the following tasks in a C#.net 2010 application:
1. start in a specified directory location.
2. check to see if a specified subfolder exists.
3. if the specified folder does not exist, create the subfolder called customer1.
4. if the subfolder called 'docs' does not exist, create that folder.
5. if the type of document type is '*.pdf' or '*.doc' place the data file in the subfolder called
'docs'.
if the document type is of any other document type, place that document in folder level where called 'customer1'.
Thus I am wondering if you can tell me and/or point me to references that will show me how to accomplish all and/or parts of the steps I would like to accomplish listed above my showing me showing me code and/or pointing me to links that will show me how to accomplish this goal?
|
|
|
|
|
What have you tried? Where are you stuck?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
If I were you I would be checking out the System.IO namespace.
Why is common sense not common?
Never argue with an idiot. They will drag you down to their level where they are an expert.
Sometimes it takes a lot of work to be lazy
Please stand in front of my pistol, smile and wait for the flash - JSOP 2012
|
|
|
|
|
I'v got this contacts file:
<?xml version="1.0" encoding="utf-8"?>
<Contacts>
<Contact>
<ContactId>0</ContactId>
<Prefix>
</Prefix>
<FirstName>Kevin</FirstName>
<MiddleName>Marois</MiddleName>
<LastName>Brian</LastName>
<Suffix>
</Suffix>
<Birthday>1965-10-11</Birthday>
<Title>Senior Software Engineer</Title>
<Comments>has 25 years of development experience</Comments>
</Contact>
<Contact>
<ContactId>1</ContactId>
<Prefix>Dr.</Prefix>
<FirstName>Henry</FirstName>
<MiddleName>DeCarlo</MiddleName>
<LastName>G</LastName>
<Suffix>III</Suffix>
<Birthday>1965-10-11</Birthday>
<Title>Oral Surgeon</Title>
<Comments>His office is over on 23rd street</Comments>
</Contact>
<Contact>
<ContactId>2</ContactId>
<Prefix>
</Prefix>
<FirstName>Mattew</FirstName>
<MiddleName>Damon</MiddleName>
<LastName>Paige </LastName>
<Suffix>
</Suffix>
<Birthday>1970-10-08</Birthday>
<Title>Actor</Title>
<Comments>Excellent actor</Comments>
</Contact>
</Contacts>
I want to delete a contact given the ContactId. So far I have:
public void DeleteContact(int ContactId)
{
XmlDocument doc = new XmlDocument();
doc.Load(XMLFile);
var path = "/contacts/contact[@ContactId='" + ContactId + "']";
XmlNode t = doc.SelectSingleNode(path);
t.ParentNode.RemoveChild(t);
doc.Save(XMLFile);
}
But this isn't right. What's the right way to do this?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: But this isn't right.
That hardly describes the problem very well.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
ya, but "What's the right way to do this" does.
If it's not broken, fix it until it is
|
|
|
|
|
The technique you present is the "right way" to implement the technique you present.
|
|
|
|
|
|
ya, I know. I just got tis example from some blog, and it doesn't do what I thought it did.
Lemme ask this, know any decent beginners tutorials on working with XML in C#?
If it's not broken, fix it until it is
|
|
|
|
|
I often reference the W3Cschools (except it's blocked at work ). I also carry a copy of "XSLT 1.0 Pocket Reference" (O'Reilly) with me, but it has very little information on XPath. At home I have a copy of the XML Bible, but it's more than ten years old now.
My best tool is a console application I call XpathTester which allows me to specify an XML file and an XPath and it generally tells me I'm an idiot. I used it to determine the XPath you were seeking.
I really need to write an article on XPath...
|
|
|
|
|
PIEBALDconsult wrote: I really need to write an article on XPath...
Please do..
I'v got 20+ years of of dev experience, but honestly, I'v only worked with XMl a few time, and that was with Visual FoxPro years ago.
If it's not broken, fix it until it is
|
|
|
|
|
OK, now I've tried it.
You only use @ when ContactId is an attribute; try [ContactId and watch your capitalization.
modified 28-Aug-12 18:12pm.
|
|
|
|
|
Hi,
I'm not well versed on event handling and I'd like to pass a color to this method, instead of having it choose the color based on the value of e.index. Can anyone tell me how to change the method below to do that?
Thanks for reading.
void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index > -1)
{
if (e.Index == 0)
e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
else if (e.Index == 1)
e.Graphics.FillRectangle(Brushes.Green, e.Bounds);
else
e.DrawBackground();
using (Brush textBrush = new SolidBrush(e.ForeColor))
{
e.Graphics.DrawString(lbxOutput.Items[e.Index].ToString(), e.Font, textBrush, e.Bounds.Location);
}
}
}
|
|
|
|