|
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);
}
}
}
|
|
|
|
|
There is no way to change the signature of an event handler that handles an event from the framework.
You'll have to write a separate function that determines what color to use, then call that function from within the event handler.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
Thanks for the reply.
I tried altering the DrawItemEventArgs e but could not and tried using something like:
void listBox_DrawItem(object sender, DrawItemEventArgs e, string color)
but that wouldn't work either, so I'm a little stumped.
How can I pass an additional variable to void listBox_DrawItem? If I can figure out how to do that, I'll be able to do the rest.
|
|
|
|
|
And how do you suppose you'll pass the additional parameter? Isn't it the framework that calls your handler (listBox_DrawItem ) ?
As I said, you cannot change the signature of the function from what the framework expects it to be.
The way to solve your problem is to have a separate function that gets called from within the event handler:
void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
Color drawColor = GetColorFromItem(e.Index);
.....
}
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
Yes you confirmed my earlier failures , I was hoping you could help prod me in the direction of success with some elaboration on your suggested solution.
If I cannot pass a variable to the method, do I need to have the method check some global variables for it to be able to know which color? Is that what you were thinking?
|
|
|
|
|
Oh I see. Well, I would say the solution really depends upon how you determine what color needs to be used.
Is it from a lookup table? Is it computed from some numerical values? Or maybe it's from an enumeration?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Hi Richard,
I don't have the code here at home, I'd like to set the color each time I call the event and then set it back to the default with the following line of code. Maybe something like
void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
if (e.Index > -1)
{
if (globalFlag == "red")
e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
else if (globalFlag == "green")
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);
}
}
}
but I tried the above before and I couldn't get the line
e.Graphics.DrawString(lbxOutput.Items[e.Index].ToString(), e.Font, textBrush, e.Bounds.Location);
to function properly, so I was hoping for some wisdom with that.
|
|
|
|
|
turbosupramk3 wrote: to function properly
What was it doing wrong?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
I can't pass the string, of what I want to write to the list box, in the event handler it uses [e.index].ToString() to pass text, but I'm back at my original problem of not being able to pass any additional variables to the listBox_DrawItem method so that I can tell it not only which color to use, but what string I want it to write to the listbox.
Any ideas on how to get around this limitation?
|
|
|
|
|
turbosupramk3 wrote: Any ideas on how to get around this limitation?
Yes, you implement a separate function that returns the correct string to use, and then you call that function from within the event handler.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|