|
I have a solution, it may not be the best, but I find it works. Say you have two input boxes, one for login, the other for password. What I did was set up a connection to the database, as usual, but, I made my query find all the usernames that matched the username inputed. If this fails, you know the username is invalid. Else, it will check the password, and you will know then if it is incorrect. Here is the code I used - try to use an error provider rather than the messagebox, but this should explain things a bit better.
string s = "Initial Catalog="+db+";Data Source="+srv+";UID="+uid+";pwd="+ps+"";
cnn.ConnectionString = s;
cnn.Open();
if(TxtUid.Text == Empty || TxtPass.Text == Empty)
{
MessageBox.Show("UserID or Password can not be left blank!","Login Fail",MessageBoxButtons.OK,MessageBoxIcon.Error);
TxtUid.Focus();
}
else
{
sda = new SqlDataAdapter("Select usrPassword, usrFullName from users where usrName = '"+ TxtUid.Text +"'",cnn);
ds = new DataSet();
sda.Fill(ds);
dt = ds.Tables[0];
if(dt.Rows.Count == 0)
{
MessageBox.Show("The username specified does not exist","Login Fail",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
else
{
dr = dt.Rows[0];
string pass = dr[0].ToString();
string name = dr[1].ToString();
if(TxtPass.Text == pass)
{
Current.Visible = false;
ApplicationData.userNameConst = TxtUid.Text;
ApplicationData.userNameFullConst = name;
frm.Show();
}
else
{
MessageBox.Show("Password does not match username '"+ TxtUid.Text +"'","Login Fail",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
}
|
|
|
|
|
Just throwing my 2.5 cents into the conversation. As mentioned earlier, it is best not to ever tell a user if the user or password is incorrect. If you do, you just cut your security drastically. If person that is trying to get into the system finds a name that is valid, then they just have to try figuring out the password. If you just say they entered an invalid user name or password, they will never know when the guess one or the other.
User friendly is fine and long as it does not hinder security.
Rocky Moore <><
|
|
|
|
|
Oh, sorry, thought you wanted to know which one was in error to display a message to the user. Not quite sure then why you would care which one was at fault.
Rocky Moore <><
|
|
|
|
|
Hi
When you show the ICQ window, if it is docked to a side of the screen, all maximized windows shrink to show it all.
How can i do something similar ?
Thanks
|
|
|
|
|
Okay -- this is not going to tell you how to do it....but you might have a direction to begin your search with this.
The ICQ process as you describe it sounds like it is implementing inside a taskbar object. Much like the taskbar in the OS and with Office explorer -- with they remain on screen, the maximized window fit to the remaining destop realty. So I'd suggest you start looking for a taskbar control and find out what its' limititations are for doing what you want.
MJ
_____________________________________________
The world is a dangerous place. Not because of those that do evil, but because of those who look on and do nothing.
|
|
|
|
|
Hi there,
I'm a self-learning newbie to .NET and C#, so I do not have enough knowledge to solve this problem, would appreciate any help please.
I wrote this console executable program (simply just moving files from one folder to another if some condition is matched), it runs fine on my computer but not on other computers that doesn't have the .NET Framework installed.
At first I got the error of missing mscoree.dll. After putting that file, I got a different error:
"Please set registry key HKLM\Software\Microsoft\.NETFramework\InstallRoot to point to the .NET Framework install location"
What should I do so that it will run on other computers running Windows that don't have the .NET Framework?
Thank you,
Lynn
|
|
|
|
|
lynnday wrote:
What should I do so that it will run on other computers running Windows that don't have the .NET Framework?
Install the .NET framework on them. All .NET applications must have the .NET Framework installed in order to run.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
When using params is it posible to get the name of the parameter passed or only the value?
Params is useful when you are not sure of the number of parameters, but if I'm not sure of the number, how can I be sure enough to blindly say:
FirstName = paramList[0];
LastName = paramList[1];
Thanks,
Robert
|
|
|
|
|
Nevermind,
I just spent 5 hours over-thinking the simplest thing. I'm always trying to use a ray gun.
Robert
|
|
|
|
|
Rbledwards wrote:
I just spent 5 hours over-thinking the simplest thing. I'm always trying to use a ray gun.
Don't you hate that? And then the overwhelming feeling of "How stupid can I be?" when you see that there really is an easier way to do it...
I once spent an entire day trying to rewrite something that was already in the .NET framework...that was depressing...
youd ebtter bnot be taki8ng agvantage o f my mental abilites!1
-David Wulff one night over MSN while totally plastered
|
|
|
|
|
Twice recently I've tried all kinds of things to get something to work, only to find out that I forgot to convert a numeric value to double before comparing. You'd think I'd learn...
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
jdunlap wrote:
You'd think I'd learn...
[humble] It's what makes us human.....[humble]
Nick Seng (the programmer formerly known as Notorious SMC)
God, I pity me! - Phoncible P. Bone
|
|
|
|
|
How do I put my program at the top of the process priority?
/\ |_ E X E GG
|
|
|
|
|
Process curProcess = Process.GetCurrentProcess();
curProcess.PriorityClass = ProcessPriorityClass.High;
Mind you, you have got to be very careful about what you do with this. You could find yourself with a totally unresponsive system. In general, messing about with priorities to give your app more oomph is only masking a deeper problem.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
By default without messing with anything, what is the process priortiy set at?
and is this using
using System.Threading;
???
|
|
|
|
|
eggie5 wrote:
By default without messing with anything, what is the process priortiy set at?
Normal.
And you're using the System.Diagnostics namespace. The difference between setting thread priority and setting process priority is that setting it at process level changes the priority of all threads within the current process...whereas setting thread priority sets the level of only the current thread...other threads in the same process would remain unchanged.
I have also lived some years in Spain, and there people don't accept that you speak bad spanish. I usually compensate by speaking loud and accusing people of being stupid because they don't understand me. It usually works quite well.
-jhaga on non-native languages
|
|
|
|
|
I know this is off-topic, but where would I go to make suggestions for the improvement of C# and the .NET Framework?
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I am using the following to open and write and encryped datafile.
FileStream fout = new FileStream(OptionsDataFile, FileMode.Create, FileAccess.Write);
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fout, tdes.CreateEncryptor(new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125}
,new byte[] {216,237,102,42,142,11,133,104,}),
CryptoStreamMode.Write);
ASCIIEncoding AE = new ASCIIEncoding();
and the following to decrypt.
FileStream fin = new FileStream(OptionsDataFile, FileMode.Open, FileAccess.Read);
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
CryptoStream encStream = new CryptoStream(fin, tdes.CreateDecryptor(new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125}
,new byte[] {216,237,102,42,142,11,133,104,}),
CryptoStreamMode.Read);
ASCIIEncoding AE = new ASCIIEncoding();
int tempByte = new int();
byte[] inBytes = new byte[(int)fin.Length];
encStream.Read(inBytes,0,(int)fin.Length);
When it gets to the read I get the following.
An unhandled exception of type 'System.Security.Cryptography.CryptographicException' occurred in mscorlib.dll
Additional information: Bad Data.
Anyone have any ideas why. Everything is the same for the write. I just do not get why the data would be bad.
|
|
|
|
|
Not sure what's going on for you. Maybe it's something in the code you *don't* show <g>.
The following works just fine for me (I separated out the creation of some the objects into separate statements for readability):
class Class1 {
static void Encrypt(string inputFile, string outputFile) {
FileStream fsin = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
FileStream fsout = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
byte[] key = new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125};
byte[] iv = new byte[] {216,237,102,42,142,11,133,104};
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
ICryptoTransform t = tripleDes.CreateEncryptor(key, iv);
CryptoStream cs = new CryptoStream(fsout, t, CryptoStreamMode.Write);
int len = (int) fsin.Length;
byte[] buffer = new byte[len];
len = fsin.Read(buffer, 0, len);
cs.Write(buffer, 0, len);
cs.Close();
fsout.Close();
fsin.Close();
}
static void Decrypt(string inputFile, string outputFile) {
FileStream fsin = new FileStream(inputFile, FileMode.Open, FileAccess.Read);
FileStream fsout = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
byte[] key = new byte[] {22,184,62,104,66,100,202,17,91,254,197,181,224,62,36,138,128,227,146,111,134,83,241,125};
byte[] iv = new byte[] {216,237,102,42,142,11,133,104};
TripleDESCryptoServiceProvider tripleDes = new TripleDESCryptoServiceProvider();
ICryptoTransform t = tripleDes.CreateDecryptor(key, iv);
CryptoStream cs = new CryptoStream(fsout, t, CryptoStreamMode.Write);
int len = (int) fsin.Length;
byte[] buffer = new byte[len];
len = fsin.Read(buffer, 0, len);
cs.Write(buffer, 0, len);
cs.Close();
fsout.Close();
fsin.Close();
}
static void Main(string[] args) {
Console.WriteLine("Starting encryption...");
Encrypt(@"c:\test.txt", @"c:\test.enc");
Console.WriteLine("...done");
Console.WriteLine("Starting decryption...");
Decrypt(@"c:\test.enc", @"c:\test.dec");
Console.WriteLine("...done");
Console.ReadLine();
}
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
The problem with the orginal code is I was not Seeking to the beginning of the stream.
|
|
|
|
|
I'm borrowing some code from Pavel's Command Prompt Explorer Bar installer to use in my own explorer bar's installer.
Recently I've been thinking that using an assembly version like "1.0.*" (hence, for example, "1.0.1304.25935") would be useful, at least for development and debugging purposes. (Someone please point out the cons to this idea!)
Well, anyway, Pavel's installer basically exists to register the assembly, and unregister the assembly at uninstallation. So it all comes down to getting the relevant assembly so it can be fed to RegistrationServices.RegisterAssembly().
Currently the code for getting the relevant assembly looks like this:
Assembly VisITBarAssembly
{
get
{
return AppDomain.CurrentDomain.Load("VisIT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4d504ee06f99380a");
}
}
This works because the version is hardcoded to "1.0.0.0" in Installer.cs as well as AssemblyInfo.cs. I'd like to remove this string from Installer.cs so I can only worry about AssemblyInfo.cs whenever I want to bump up a version number. (Bonus points if I could remove the need to change both AssemblyInfo.cs and the version number in the Setup project! Additional bonus points if I can access the Setup project's "Manufacturer" etc. fields from the application, but I guess the best (or only?) solution would be to use the Registry.)
So what are some good ways to go about this? I think using the Registry might be one way to go about it, having to store the assembly's full name somehow (programmatically) in a registry entry. Personally I think it would be nicer to avoid it, but hey! If I assume a constant GUID, then I could look it up in the registry (it's already stored there, but then again, this might implicitly get stored from the RegisterAssembly call).
It would be even nicer, I think, to have a dynamic GUID, that allows the GUID to change with the Product GUID (set in the Setup project), but I don't know if that's feasible.
And furthermore, what can I do with the savedState object that is an argument to so many Installer event handlers?
Any tips, comments, or smooth suggestions?
Thanks,
Arun
|
|
|
|
|
Alright,
I have some source code libraries that help me convert text into pdf417 (2d) barcodes. That all works fine. Heres my issue, the
public sbyte[]createbarcode() method gives me an array of sbytes with which to create a bitmap. I want to then print this bitmap. My question is, are there any gdi junkies out there who can point me in the right direction as far as creating a bitmap through a big old sbyte array?
Thanks for the help in advance,
Ryan
|
|
|
|
|
System.IO.MemoryStream stream = new System.IO.MemoryStream(b, true);
stream.Write(bytes, 0, bytes.Length);
Bitmap bmp = new Bitmap(stream);
|
|
|
|
|
I would really need some help with using the WIN32 API SendMessage() from C#. I want to start a program from mine, but if it's already an instance open, I wanna find that window and send it a message of a file to load instead of starting a second instance.
I'll do this through the FindWindow and OpenIcon methods, but how do I send my message to the other window?
I know how to get my own message ID's and so my second application will listen for a specific custom message, but how do I send the actual data to it? I've found something called COPYDATASTRUCT or something, but how to use it? and from C#
I'd really appreciate some help I haven't done any windows programming before and it's kind of a Jungle of structs and defines =) And on top of that the Marshal-As-issues...
have a nice day i'd appreciate some help on this one. really.
|
|
|
|
|
I now know that i should use WM_COPYDATA together with a COPYDATASTRUCT. but how do I get something corresponding to a pointer from my object, to pass as lpData in the struct?
I guess that's my main question really. And also what types to use.
|
|
|
|
|