|
I understand that a developer can circumvent my app - I'm talking about your average user with no programming experience. This app isn't targeted to programmers.
If it's not broken, fix it until it is
|
|
|
|
|
A user doesn't need any programming experience to circumvent your security. They just need a passing knowledge of permissions.
|
|
|
|
|
Kevin Marois wrote: This app isn't targeted to programmers. You are effectively asking how to keep something private on a machine that ain't yours. You could 'hijack' the data, encrypt everything and keep your encryptionkey on a server. Not a good way to formulate it, but the question here is ownership. If you don't want them to access a file, then don't have it on the local machine.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Open the file in your app, and do not close it while the application is running. Make sure you set FileShare.None when opening the file. Of course, when you close your app, Windows will close the file, and now the user can access it.
|
|
|
|
|
This is related to core operating system fundamentals. If you control the environment (ie are an administrator on the machine where it's installed) you can lock it down. Otherwise, not gonna happen and any attempt on a distributed application would reek of malware.
"There are three kinds of lies: lies, damned lies and statistics."
- Benjamin Disraeli
|
|
|
|
|
Suppose I have the following strings
Sample1[Model:M1; Year:1990]
Sample2[Model:M3; Year:1997]
I can get the index of the string Sample1 but how do I get the indexes of the first occurrence of the delimiters [ and ] after Sample1?
modified 12-Sep-16 0:30am.
|
|
|
|
|
The first character after 'Sample1 will have an index equal to the length of 'Sample1, if you know that first search string will always have a [ after it, then you can just use that, else use 'IndexOf which will return the index of the first occurrence.
If you are sure that there is only one ] in the search string, you can just use 'IndexOf on the string.
If there could be multiple [ :
int lastindexof = searchString.ToList().FindLastIndex(']');
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Hi, thanks for replying. Your suggestion will get the indexes of all the delimiters after the string Sample1. However, what if I want only the indexes of the delimiters immediately after the string Sample2 or immediately after the string Sample5, Sample10, etc?
|
|
|
|
|
Hi, I made the assumption, in replying to your question, that you were parsing a file one-line-at-time, so the issue of possible multiple bracket characters would not arise.
But, there's a relatively easy way to confine your search to the first ] character after the first [ character found:
private string test = @"Sample1[Model:M1; Year:1990]Sample2[Model:M3; Year:1997];"
List<Point> bracketIndexes = new List<Point>();
char rBrack = '[';
char lBrack = ']';
int loc = 0;
int limit = test.Length;
int brackStart, brackEnd;
while (loc < limit)
{
brackStart = test.IndexOf(rBrack, loc);
if (brackStart == -1) break;
brackEnd = test.IndexOf(lBrack, brackStart + 1);
if (brackEnd == -1) break;
loc += brackEnd;
bracketIndexes.Add(new Point(brackStart, brackEnd));
loc++;
}
foreach (Point pt in bracketIndexes)
{
Console.WriteLine("{0} at {1} : {2} at {3}", test[pt.X], pt.X, test[pt.Y], pt.Y);
};
Notes:
1. I used a 'Point structure here to hold the discovered indexes for convenience ... as an alternative to using a Struct or a Tuple.
2. I'm allergic to writing a 'while loop without an exit condition, but, in this case, the loop is going to be exited the first time either of the two calls to 'IndexOf return -1.
3. Somebody could come along and show a much shorter way of doing this with RegEx (?), but since i am "RegEx challenged," that's a guess. Similarly, you could use Linq here, perhaps some form of 'GroupBy, but, my experience is that this type of operation is best done with loops: better performance. That opinion is one I have formed more from reading opinions of people I regard as at a level of technical depth much deeper than mine ... than from personal experimentation.
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
Use a Regex:
Regex findEm = new Regex(@"(?<=Sample)(?<SampleNo>\d+)(?<Start>\[)(?<Data>.*?)(?<End>\])");
string input = "Sample1[Model:M1; Year:1990]";
Match m = findEm.Match(input);
if (m.Success)
{
Console.WriteLine("Sample {0}: {1}{2}{3}\n {4}, {5}",
m.Groups["SampleNo"].Value,
m.Groups["Start"].Value,
m.Groups["Data"].Value,
m.Groups["End"].Value,
m.Groups["Start"].Index,
m.Groups["End"].Index);
}
Result:
Sample 1: [Model:M1; Year:1990]
7, 27
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Excellent, I had an intuition that while I composed, and then revised, my loop-de-loop extravaganza, someone, like you, who spoke RegEx, would show up
«There is a spectrum, from "clearly desirable behaviour," to "possibly dodgy behavior that still makes some sense," to "clearly undesirable behavior." We try to make the latter into warnings or, better, errors. But stuff that is in the middle category you don’t want to restrict unless there is a clear way to work around it.» Eric Lippert, May 14, 2008
|
|
|
|
|
They aren't that difficult to compose, they are just nasty to read!
Have a look at this: Expresso[^] - it's free, and it examines, explains, and generates Regular expressions. It even creates the C# or VB code for you to use them.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
You could write an extension method to get the string between the delimiters:
public static string BetweenChars(this string text, char left, char right)
{
string result = string.Empty;
int leftPos = text.IndexOf(left, 0)+1;
int rightPos = text.LastIndexOf(right);
if (leftPos >= 0 && rightPos > leftPos)
{
result = text.Substring(leftPos, rightPos - leftPos);
}
return result;
}
Or one to just get the delimiter positions
public static void DelimiterPos(this string text, char left, char right, out int leftPos, out int rightPos)
{
string result = string.Empty;
leftPos = text.IndexOf(left, 0);
rightPos = text.LastIndexOf(right);
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Thank you all. I will tryout all of your suggestions and see which one suits my needs.
|
|
|
|
|
Hi, I need help. Is it possible to compare two textboxes first then display if they are the same or not in another textbox. this is what I have so far:
if (textBox1.TextLength == 3)
{
textBox2.Focus();
}
if (textBox2.TextLength == 3)
{
textBox1.Focus();
}
if (textBox1.Text == textBox2.Text)
{
textBox3.Text = "PASSED";
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}
if (textBox1.Text != textBox2.Text)
{
textBox3.Text = "FAILED";
}
My issue here is that the moment I input something in textbox1, textbox3 will show FAILED already.
Thanks in advance.
BTW, I cant use btnclick event.
|
|
|
|
|
This is really a state machine but not written like one, so probably you got confused about what state to do what in, so everything happens all the time.
I don't really know either, because you don't say how it should work, but maybe it's meant to work like this:
state 0 [entry]: textbox 1 is focused (refocus if it loses focus?). If the text length reaches 3, go to state 1. Maybe do something about length > 3 too, such as cut off the extra and then go to state 1.
state 1: textbox 2 is focused (refocus as needed). If the text length reaches 3, compare text. If passed, clear boxes, put PASSED in box 3, and go to state 0. If failed, go to state 2.
state 2: put FAILED in box 3 and just die or something, not clear from your code what should happen here. Maybe allow box 2 to be edited until pass? Who knows.
|
|
|
|
|
Your code doesn't make any sense.
I assume you're using the TextChanged event to determine when to compare the two fields (if you're not, you should be).
When the text in one text box or the other changes, it should be immediately compared against the text box, and the SECOND textbox should be highlighted as invalid if the contents don't match (because any sane person would assume the first text box is the determining factor).
Further, I'm not sure why you're clearing the contents on the text boxes when in a "PASS" condition, but whatever.
Lastly, you shouldn't be programmatically changing focus between controls unless it makes sense to do so (form initialization, or process-specific control selection by the user).
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Please use the pre tags when adding code snippets (the code button in the toolbar)
I think you want something like this:
if (textBox1.TextLength == 3)
{
textBox2.Focus();
}
if (textBox2.TextLength == 3)
{
textBox1.Focus();
}
if(textbox1.TextLength == 3 && textbox2.TextLength == 3){
if (textBox1.Text == textBox2.Text)
{
textBox3.Text = "PASSED";
textBox1.Clear();
textBox2.Clear();
textBox1.Focus();
}
if (textBox1.Text != textBox2.Text)
{
textBox3.Text = "FAILED";
}
}
Quote: BTW, I cant use btnclick event.
I have no idea what you want this statement...
hope this helps.
|
|
|
|
|
2 assume their respective control dateEdit: dEditForm and dEditTo want to check the date of this control has the form 2: date from: "__ / __ / ____" and date to: 11/09/2016, which from day null and days to 1 day, must be valid as examples here dates are September 11 years his 2016 writing test code with the error message:
[CODE]
if (dEditFrom.DateTime == null && dEditTo.DateTime != null) // warning error here dEditTo.DateTime != null
{ do something ... }
[/CODE]
I using devexpress. can you help me ?
|
|
|
|
|
No, I can't - because I have no idea what you are trying to do, or how it is giving you difficulties.
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work from.
So explain in more detail exactly where it's a problem, and if there is an error message then tell us exactly what it says - copy and paste it from VS.
Show us the code that gives a problem (again, copy and paste here) and explain what it does that you didn't expect, or doesn't do that you did.
At the moment I have no idea, especially as the DateTime property of a devexpress DateEdit control is a .NET DateTime value - which is a struct, and this can't be null.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
If you're using DevExpress, doesn't it already validate as you type the date?
Generally speaking, you can validate a date entry field by using DateTime.TryParse() . If TryParse returns false, the text does not represent a valid DateTime object.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I have been working on finding case numbers in strings based on user inputted pattern. The pattern is build up by using the Characters D=Decimal , A=Aplha ,- = seperator.
This can be anywhere from DDDAAAA or DDDD-AAAA-DA-AD, most common case would be DDDD-DDDD or DDAA-DDDD , Note that a separator is not mandatory.
I have written an old-school void that creates a list of strings that represent the sequences in the pattern. For the pattern DDAA-DDD i would return this.
new List {DD,AA,-,DDD}
And then use the list to find my matches (different story)
Q: I have been trying to figure out how to do this using linq queries.
What I have so far is sort of on point, but only partialy.
var pattern = "DDDD-AA-DD";
var patternlist = pattern.GroupBy(x => x)
.Where(g => g.Count() > 1)
.Select(y => new { Element = y, Counter = y.Count() });
This will not create a separate group for all the patterns or sequences. This will only tell me that I have 6 instances of D , 2 instances of A and 2 instances of -.
I wanted to find an elegant solution to this, where I could return something like a group per sequence of a char. Note I would not want to use the values of the chars or reference the known values.
I’m not looking for something like this.
if (pattern.StartsWith("A"))
{
var tst = pattern.TakeWhile(p => p == 'C');
}
Any takers
|
|
|
|
|
I don't think the built-in LINQ methods will help you here. But it's fairly simple to implement:
public static class Patterns
{
public static IEnumerable<string> GroupPatterns(this string pattern)
{
char prev = '\0';
char[] item = new char[pattern.Length];
int itemIndex = 0;
foreach (char c in pattern)
{
if (c != prev)
{
if (itemIndex != 0)
{
yield return new string(item, 0, itemIndex);
Array.Clear(item, 0, itemIndex);
itemIndex = 0;
}
prev = c;
}
item[itemIndex] = c;
itemIndex++;
}
if (itemIndex != 0)
{
yield return new string(item, 0, itemIndex);
}
}
}
Given the input "DDDD-AAAA-DA-AD" , that will produce:
{
"DDDD",
"-",
"AAAA",
"-",
"D",
"A",
"-",
"A",
"D"
}
As to finding the matches, it might be simpler to convert the pattern to a Regular Expression[^]:
public static class Patterns
{
...
public static Regex PatternToRegularExpression(this string pattern)
{
var parts = new List<string>();
foreach (string part in pattern.GroupPattern())
{
switch (part[0])
{
case 'D':
case 'd':
{
parts.Add("\\d{" + part.Length + "}");
break;
}
case 'A':
case 'a':
{
parts.Add("[A-Z]{" + part.Length + "}");
break;
}
default:
{
parts.Add(Regex.Escape(part));
break;
}
}
}
string regexPattern = string.Concat(parts);
return new Regex(regexPattern, RegexOptions.IgnoreCase);
}
}
For the same input, this will generate the regular expression:
\d{4}-[a-z]{4}-\d{1}[a-z]{1}-[a-z]{1}\d{1}
Regexper[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
thaks for your input, 
|
|
|
|
|
LINQ isn't always the answer. This is the way I'd do it.
List<string> patternList = new List<string>();
foreach(char ch in pattern)
{
if (patternList.Count == 0 || !patternList.Last().Contains(ch))
{
patternList.Add(ch.ToString());
}
else
{
patternList[patternList.Count-1] += ch.ToString();
}
}
You could put this code into an extension method.
".45 ACP - because shooting twice is just silly" - JSOP, 2010
- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|