By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,190 Members | 847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

Strange code execution

P: n/a
Hi, I am new to C#, that is why I am not sure what kind of problem it is: Is
VS files corrupted , or something else. that is the problems description:
I am working on a small database project. I am not using any data sources
Mysql, access etc. Instead I use binary formatter to store and read data. at
the beginning the program checks username/password. it does it in the
following way:

if(form2.initialized)
{
for(int i=0; i<database.users.Count;i++)
{
User user;
user=(User)database.users[i]
s1=System.Text.ASCIIEncoding.ASCII.GetString (System.Convert.FromBase64String(user.username));
s2=System.Text.ASCIIEncoding.ASCII.GetString
(System.Convert.FromBase64String(user.password));
if(s1==form2.username.Text && s2==form2.password.Text)
{
accessmode=user.accessmode;
user.lastlogin=System.DateTime.Now;
SaveDatabase();
userlogged=true;
break;
}
}
}
if(!userlogged)
{
System.Windows.Forms.MessageBox.Show("Incorect
Username/Password.Access denied!");
Close(); //Code execution jumps here!!!
}

There is a strange problem: suppose user entered correct username/password,
that is, userogged=true, ok? surprisingly after break takes places code
execution jumps to Close() and form closes, even MessageBox.Show function
does not execute. The same occures in another code:

System.IO.Directory.CreateDirectory(df);
Form3 form3=new Form3();
form3.ShowDialog(this);
if(!form3.initialized)
{
System.Windows.Forms.MessageBox.Show("You must have at least one
administrator username and password. Try next time.");
Close();
}
execution jumps straight to Close() (not to MessageBox.Show(). if
form3.initialized==false, the program shows message box, in another case it
simply closes.
Can anyone clarify this point? May be VS files are corrupted, or there is an
error in code?

Nov 16 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
I'm not seeing a problem with your code.

1. I'd like to see the code that CALLS each of these.
2. You say that in the debugger, you are seeing the system jump to the
"close" call? Normally, I would look for things like misplaced commenting
causing a block to be balanced incorrectly, or a string that has been left
open. (One reason I don't particularly care for multi-line strings).
3. This is a good-old-fashioned stumper. If you think that some files are
corrupt, you can try creating a new project and copying the code files from
the old project. In fact, I usually consider it good practice to see if I
can extract a problem like this into a small snippet that exhibits the
behavior. That is something you can post or even share with product support
services. If you create a snippet like this, feel free to post it online.
That may help.

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"Default" <De*****@discussions.microsoft.com> wrote in message
news:EC**********************************@microsof t.com...
Hi, I am new to C#, that is why I am not sure what kind of problem it is: Is VS files corrupted , or something else. that is the problems description:
I am working on a small database project. I am not using any data sources
Mysql, access etc. Instead I use binary formatter to store and read data. at the beginning the program checks username/password. it does it in the
following way:

if(form2.initialized)
{
for(int i=0; i<database.users.Count;i++)
{
User user;
user=(User)database.users[i];
s1=System.Text.ASCIIEncoding.ASCII.GetString (System.Convert.FromBase64String(user.username)); s2=System.Text.ASCIIEncoding.ASCII.GetString
(System.Convert.FromBase64String(user.password));
if(s1==form2.username.Text && s2==form2.password.Text)
{
accessmode=user.accessmode;
user.lastlogin=System.DateTime.Now;
SaveDatabase();
userlogged=true;
break;
}
}
}
if(!userlogged)
{
System.Windows.Forms.MessageBox.Show("Incorect
Username/Password.Access denied!");
Close(); //Code execution jumps here!!!
}

There is a strange problem: suppose user entered correct username/password, that is, userogged=true, ok? surprisingly after break takes places code
execution jumps to Close() and form closes, even MessageBox.Show function
does not execute. The same occures in another code:

System.IO.Directory.CreateDirectory(df);
Form3 form3=new Form3();
form3.ShowDialog(this);
if(!form3.initialized)
{
System.Windows.Forms.MessageBox.Show("You must have at least one
administrator username and password. Try next time.");
Close();
}
execution jumps straight to Close() (not to MessageBox.Show(). if
form3.initialized==false, the program shows message box, in another case it simply closes.
Can anyone clarify this point? May be VS files are corrupted, or there is an error in code?

Nov 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.