|
Hi!
I'm developing a Winform application in C# 2.0 which access to a SQL Server Express.
Currently I'm using this connection string (app.config):
connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=MyDB;Integrated Security=True"
As you can see, currently I'm using Windows Authentication to log on the SQL Server.
I want to add a user login form and depending on which user has logged in, I will grant or deny opening some of the forms which my application has.
How should I manage these users? I was thinking in having a table with (user,password) and encrypting the password in some way.
Is there a best practice to do this?
|
|
|
|
|
User Management can be done in two ways: using LDAP (Lightweight Directory Access Protocol), will allow only thos users to log on to the application who are a part of that windows domain. This approach might be a little cumbersome as many applications do not require such tight coupling with windows domain for allowing or denying access to users, moreover, it is certainly a tedious task to use LDAP to manage access to individual forms. The other way out, is your way, creating a table for users and storing their passwords in encrypted form, now here, I suggest to create an admin table as well that will reference to the user table on the basis of unique user id, and since you plan to grant or revoke permission on users, yourself, you can also create an admin screen in your app, wherein you can enlist all users and their information and you can grant/revoke permissions there and these details will be updated in the admin table. For the encryption part of it, u can write a simple substitution cipher program that will shift the bits to either one left or one right to give you an encrypted string, or, u can use the Encryption class of the .NET F/W, I personally prefer to write my own program for encryption, as it is great fun to experiment with n-number of ways of encrypting data. Let me know if i was able to give u some headway...
cheers
|
|
|
|
|
Ok, thanks.
I was thinking in creating two tables: (Users table and ModuleAccess table)
(User,Password)
and
(User,Module)
User is the primary key for the first table.
User+Module is the primary key for the second table.
The password column actually will save the "user+password" string encrypted. I mean, there will be a LogIn form where you must enter your user and password, after that, I will encrypt the user+password string entered in the LogIn form and compare it with the one I've saved in the table.
I will use a similiar aproach to handle the modules (forms that the user can access).
Thanks!
|
|
|
|
|
i think you should define some roles and add your users in that roles...
and on form level check which role has access to which forms
|
|
|
|
|
Hi all.
The attached code works absolutely fine. However if I want to send the "encryptedString" over a socket I receive the following exception where the send fails:
"Exception: Found a high surrogate char without a following low surrogate at index: 8. The input may not be in this encoding, or may not contain valid Unicode (UTF-16) characters.
Parameter name: chars"
However, this does work over the socket in about 1 in 10 times. I have also tried to send as bytes instead of string which solved the socket problem but corrupting the data so it couldn't be decrypted using the private key after transfer.
I am using .net 1.1
Does anyone know the solution to this problem?
Thanks, Anthony
// Represents UserA generating an rsa key pair
UnicodeEncoding byteConverter1 = new UnicodeEncoding();
RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider();
string publicKey = rsa1.ToXmlString(false);
// Represents UserB encrypting a message ("hello world") with UserA's public key
RSACryptoServiceProvider rsa2 = new RSACryptoServiceProvider();
rsa2.FromXmlString(publicKey);
UnicodeEncoding byteConverter2 = new UnicodeEncoding();
byte[] bytesToEncrypt = byteConverter2.GetBytes("hello world!");
byte[] encryptedBytes = rsa2.Encrypt(bytesToEncrypt,false);
string encryptedString = byteConverter2.GetString(encryptedBytes);
// Represents UserA decrypting the message with his private key
byte[] bytesToDecrypt = byteConverter1.GetBytes(encryptedString);
byte[] decryptedBytes = rsa1.Decrypt(bytesToDecrypt, false);
string message = byteConverter1.GetString(decryptedBytes);
string msg = message;
|
|
|
|
|
Hi People,
I have a ToolStrip with some items.
When I hit some button I load a form inside a Panel and disable some of the ToolStrip menuitems.
So far so good.
Now I want to enable those menu items when I click a button on the usercontrol that was loaded in the panel control...
How do I achieve this??
btw: Im a newbie and search google, but cannot find anything :-S
TIA,
Richard
|
|
|
|
|
There's a good article here on CP about cross form communication. Short version - you define a delegate to get a method call in one form, to call a method in another. If you google delegates, you'll find tons of examples.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
|
Thanx Cristian and cocoonwls,
I did allot of reading regarding delegates but boy o boy what a information that is
As you could probably have guessed , Im a beginner in the world of C# (If have allot of VBA experience though but this is something else)
I'll try to explain what Im trying to achieve;
I have a form (MainForm).
On MainForm there is a button that loads another form (Form2) (inside a panel, dont know if that is rellevant) and disables some menuitems using "this.relatiebeheerToolStripMenuItem.Enabled = false;"
Know.. on the Form2 I need to have a button that closes the form (Form2) and sets the menu to enabled again..
There is allot of info on delegates but I can't find anything matching my ' problem'
Please help
Richard
*edit* : I made a mistake.
Actually there is one form (MainForm) and the ' form' im loading in the panel is actually a user control.
Dont know if thats makes a difference ..
modified on Monday, April 21, 2008 6:19 AM
|
|
|
|
|
Hi Richard,
There are the same(load form into panel ro show as dialog).Below is the example by using delegate;
FormMain:
public FormMain()
{
Form2 f2 = new Form2();
f2.TopLevel = false;
f2.visible = true;
this.panel1.controls.add(f2);
f2.callbackFn += new hidetoolstrip(this.abc)
}
private void abc(boolean b)
{
}
Form2:
public hidetoolstrip callbackFn;
private void button1_Click(object sender, EventArgs e)
{
callbackFn(True);
}
Class Delegate:
public delegate void hidetoolstrip(boolean b);
Above example is what the article wrote.Hope this help you
|
|
|
|
|
Hi all,
I want to create a custom combo box control which has some extra buttons. Whilst I can render the various parts of the control using "ComboBoxRenderer", the controls do not match the other Vista combo boxes. This makes any form using such comboboxes look strange because there are two flavours.
The proper Vista ComboBox controls are a rounded edged rectangle with a black down arrow (white background). When you hover the mouse over the arrow the button appears. The "ComboBoxRenderer" shows a non-highlighted button with a black down arrow on it.
How can I draw the proper Vista style combo box themed visuals AND still have it compatible with Windows XP? It would be great if someone could offer an example.
Cheers!
Lea Hayes
|
|
|
|
|
i have the same question , and don't know how to solve it,
i googled it and found here
Have you fixed it yet ?
regards
badtoto
|
|
|
|
|
Hi,
I am afraid that I was unable to find a solution to this problem. So I resorted to just having two styles of combo box in my program, doesn't look as good as it could have, but nevertheless, functional.
If you do manage to find a fix, it would be great if you could post it here as this is something that I too am still interested in.
Many thanks,
Lea Hayes
|
|
|
|
|
Hello!!
I have been googling to find a way to add an image in an rtf document, and all I've found up to now is by converting the image in a hexadecimal string... and I realy can't understant anything...
Does any one know if there is a simplier way for this, something like we use in old good html like img src and filepath?
Thanks!!!
|
|
|
|
|
Hi!
Probably the easiest way is to put the image into the clipboard and then paste into your RTB.
You won't have a lot control over how the image is being displayed, but it's very simple.
Another way is to use the corresponding OLE functions. There's an article here on CP somewhere...
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
I have a WinForms program in which I have added several icon resources.
I'm using the following code to load the icon resources:
Type assyType = GetType();
Icon icon = new Icon(assyType, "IconName.ico");
I'm getting the following exception:
Resource 'IconName.ico' cannot be found in class 'MyAppNamespace.Form1'.
I've also tried Type assyType = GetType("MyAppNamespace.Program"); with the same general result. I've verified that I've spelled the name of the ico correctly, so I'm kind of at a loss.
Does anyone have any ideas?
EDIT:
I've also tried this:
Icon icon = new Icon(System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("MyAppNamespace.IconName.ico"));
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
modified on Sunday, April 20, 2008 10:49 AM
|
|
|
|
|
The easiest way is to add the icon to the default resources.resx file and access it through the static Properties.Resources class that gets automatically generated. Otherwise, make sure the file is marked as an embedded resource. Try this for your constructor:
Icon icon = new Icon(typeof(this), "IconName.ico"); This assumes, of course, that the icon is located in the same assembly as the calling code.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
I checked, and most of the icons were labeled as "Content", so I changed them to "Embedded", but that had no effect at all.
I also tried typeof(this) in the icon's constructor call, and received the compiler error Type expected for "this".
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: I also tried typeof(this) in the icon's constructor call, and received the compiler error Type expected for "this".
Sorry...try this.GetType() or typeof([some custom type in the same assembly as the icon]) .
John Simmons / outlaw programmer wrote: so I changed them to "Embedded", but that had no effect at all.
Right, that won't have any visible effect. What you're doing is telling the compiler to embed the icons as resources into the assembly. The "Content" tells it to copy the files to the output directory.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Well, the GetType() thing just isn't working, but I did figure out how to get the reflection thing to work - I had to use the entire namespace path to get to the embedded files like so (I broke it out to allow easier for me to debug and to allow for formatting here:
string iconName = "MyIcon";
string resolvedName = string.Format("MyAppNamespace.Resources.{0}.ico", iconName);
Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resolvedName);
m_trayIcon.Icon = new Icon(iconStream);
iconStream.Close();
I'm concerned about not being able to do it with GetType() since so many people see to be doing it that way. I know - I should probably be happy to have found a way to do what I want and leave well enough alone, but I really would like to know what I did wrong there.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Well, first is that I'm glad you found a work around. One suggestion would be to wrap the stream in a using block, like this:
string iconName = "MyIcon";
string resolvedName = string.Format("MyAppNamespace.Resources.{0}.ico", iconName);
using (Stream iconStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resolvedName))
{
m_trayIcon.Icon = new Icon(iconStream);
} As far as getting the GetType() method working, I think the problem is due to the namespace where your icon resources are located. From the MSDN docs on this constructor:This constructor combines the namespace of the given type with the string name of the resource and looks for a match in the assembly manifest. For example you can pass in the Control type and Error.ico to this constructor and it will look for a resource named System.Windows.Forms.Error.ico. Since the icon is located in a "MyAppNamespace.Resources" namespace, you would need to give it a type in the "MyAppNamespace.Resources" namespace or you could give it a type in "MyAppNamespace" and use "Resources.MyIcon.ico" as the icon name.
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
I have two tables: Author and Publication. Publication has a Foreign Key that's named AuthorID. I want to be able to sort my data, but if I write:
publicationBindingSource.Sort = "AuthorID ASC";
it will sort foreign keys (integers), and not the actual data that they're pointing at.
Any idea how to sort this out?
Thanks
|
|
|
|
|
Hi All;
I have a class that contains a private dictionary
Dictionary<Int32, Boolean> _numbers = new Dictionary<Int32, Boolean>();
When I start working on a particular calculation I initialize _numbers using
for (Int32 i = 0; i < _Max; i++)
_numbers.Add(i, true);
This this initialization works fine until I set _Max > 23997906 after which I start getting OutOfMemoryException when i = 23997907.
I am lost as how to solve this exception and would appreciate any help or guidelines.
Tnx
Ian
No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced.
|
|
|
|
|
Hi,
I suspect the (generic) collections of storing objects all the time, even when the intended
type is a value type. Now each object has an administrative cost of at least 32 bytes,
so 24 million integers in a collection would amount to at least 1 gigabyte of memory
or address space.
So you might get a bit further by adding memory or enabling the 3GB switch, but the
gain would be limited anyhow.
If you need that many numbers, I suggest you don't store them (how long does it take
to fill the collection?); instead use an enumerator and possibly the yield keyword to
implement it. That way nothing gets stored, the numbers will be generated one at a time,
"just in time".
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Don't forget that Boolean takes up 1 byte of memory.
|
|
|
|
|