473,419 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,419 software developers and data experts.

Strange code execution

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
1 1930
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: cournape | last post by:
Hi there, I have some scientific application written in python. There is a good deal of list processing, but also some "simple" computation such as basic linear algebra involved. I would like to...
6
by: Ryan | last post by:
I came across a situation that I've been unable to explain and was hoping somebody had an answer: I had written an update query which was taking about 8 seconds to run and considered it too...
4
by: Praveen_db2 | last post by:
Hi All I am getting strange errors in my db2diag.log can any one tell me what these errors mean?? Following is the code from my db2diag.log...
0
by: adamalton | last post by:
I'm trying to investigate the way PHP behaves in relation to timeouts and included scripts. PHP seems to do very strange things when scripts that include other scripts timeout, or when the included...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.