|
Using the registry is not recommended for .NET applications. Instead (to the original poster) you can still encrypt the password and save it to the .config file (named yourappname.exe.config) either in the <appSettings> or to your own section that you can create using an implementation of IConfigurationSectionHandler . Using .config files is far more robust for .NET apps because it centralizes application settings.
The idea would still be the same, though, and there's many ways to accomplish the task.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Storing (and ESPECIALLY retrieving) a password is never secure. Why would you want to retrieve the password from a file? You should never have to retrieve a password, it should always be given to you by the user.
|
|
|
|
|
I'm not a security expert, but there's one thing I've picked up...
In general, you should never store a password. I think it's a bad idea to even store an encrypted one. If you store an encrypted one and your keys are compromised, decrypting it is trivial.
Store the hash of a password and "salt" that hash. It's preferable to have your salt have something in it that varies per user. Assuming the user-list and password hash is compromised, salting prevents a hacker from gaining easy entry. Having your salt have something unique per user in it prevents comparing a known account with a known password and finding another account with that same password.
Then hash what they input and check it against the stored hash.
Do a search for hash's and salt for some more info.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
I try to retrieve the bitmap displayed in a static control with a call to appropriate windows API.
I get a non zero bitmap handle, but the following code generate the exception reported.
imageHandle= SendMessage (handle,STM_GETIMAGE,IMAGE_BITMAP,0);
Bitmap bitmap = Bitmap.FromHbitmap(imageHandle);
System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+.
What's the problem?
thanks.
|
|
|
|
|
Why is your managed app getting a handle to an image using SendMessage ? I assume the image is in a native control? Is it in another application apart from yours? If so, handles are not valid across application boundaries.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Yes, im trying to get the icon of a label control (Static) belonging to
a dialog popped up by another app.
Window handle remains valid across application context, i'm able to
enumerate all the components contained in dialogs owned by other applications
and get all their properties, but every thing fails when i try to access images.
There's a way to have managed code to access other application contexts?
thanks.
|
|
|
|
|
|
Roger J wrote:
since it is free i hope i wont get too flamed for this ..
As long as the code is free, its ok, you are under obligation to submit an article within the next 90 days.
leppie::AllocCPArticle("Zee blog"); Seen on my Campus BBS: Linux is free...coz no-one wants to pay for it.
|
|
|
|
|
Just an FYI:
You should take a look at that page with the Mozilla 1.5 browser. It gets really screwed up.
I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.
-David St. Hubbins
|
|
|
|
|
What is an easy way to change a return key to act like the tab key in a c# windows application for all controls on a windows form?
|
|
|
|
|
You could handle the Control.KeyDown event and use SendKeys.Send to send a tab:
this.myForm.KeyPreview = true;
this.myForm.KeyDown += new KeyEventHandler(this.myForm_KeyDown);
private void myForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
e.Handled = true;
SendKeys.Send("{TAB}");
}
} There's other ways through P/Invoking PostMessage , but doing it this way should work and keeps all your code managed.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you for your reply.
I had tried this, but I tried it again (using the designer and adding the code to check: if(e.KeyCode == Keys.Enter) and what I found again was that this only seems to work if you place the _KeyDown check for each control rather than at the form level. Is there a way to trap the key stroke globally since setting the: [this.myForm.KeyPreview = true;this.myForm.KeyDown += new KeyEventHandler(this.myForm_KeyDown);] does not seem to do it?
|
|
|
|
|
That's why I included myForm.KeyPreview = true in my example code.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thank you again for your response.
I tried as you suggested (the code you suggested is generated by the .NET studio by changing KeyPreview in the form properties to the "True" value) and the same result occured ... the return key was not trapped and the cursor did not advance to the next tab field. The following code was generated:
this.KeyPreview = true;
where "this" is the form.
When I changed the event handler for each field to access the function "GlAcctMaster_KeyDown", it worked fine. It generated the following code:
this.Text_Description.KeyDown += new System.Windows.Forms.KeyEventHandler(this.GlAcctMaster_KeyDown);
I much appreciate your responses.
|
|
|
|
|
Im looking for a way to unblock a Socket when then Accept() i called.... I´ve been looking at setSocketOption() but can´t get it to work.
Hope that someone can help me..
Thanks in advance
Søren Christensen
|
|
|
|
|
First use the SetSocketOption to have a timeout as such.
YOURSOCKET.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 10000);
(The third paramater is the timeout in Milliseconds)
Then put the Accept in a Try/Catch block because if it does time out it will cause a SocketException.
|
|
|
|
|
I´ve tried that, but it still doesn´t work, the exception is newer thrown...
<br />
listeningSocket.SetSocketOption( SocketOptionLevel.Socket, <br />
SocketOptionName.ReceiveTimeout, 10000 );<br />
<br />
try<br />
{<br />
connection = listeningSocket.Accept();<br />
}<br />
catch( SocketException )<br />
{<br />
}<br />
<br />
can you see any error?
Søren
|
|
|
|
|
I'm trying to make a call on a singleton remoting object
that is running using tcp channel.
I get the Transparent Proxy using Activator.GetObject
with no problems when I make the first call on the
remoting object.
This is part of the exception i get.
_remoteStackTraceString
=======================
_remoteStackTraceString "\nServer stack trace:
\n at
System.Runtime.Serialization.Formatters.Binary.BinaryAssem
blyInfo.GetAssembly()\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectReade
r.GetType(BinaryAssemblyInfo assemblyInfo, String name)
\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectMap..
ctor(String objectName, String[] memberNames,
BinaryTypeEnum[] binaryTypeEnumA, Object[]
typeInformationA, Int32[] memberAssemIds, ObjectReader
objectReader, Int32 objectId, BinaryAssemblyInfo
assemblyInfo, SizedArray assemIdToAssemblyTable)\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectMap.C
reate(String name, String[] memberNames, BinaryTypeEnum[]
binaryTypeEnumA, Object[] typeInformationA, Int32[]
memberAssemIds, ObjectReader objectReader, Int32
objectId, BinaryAssemblyInfo assemblyInfo, SizedArray
assemIdToAssemblyTable)\r\n at
System.Runtime.Serialization.Formatters.Binary.__BinaryPar
ser.ReadObjectWithMapTyped(BinaryObjectWithMapTyped
record)\r\n at
System.Runtime.Serialization.Formatters.Binary.__BinaryPar
ser.ReadObjectWithMapTyped(BinaryHeaderEnum
binaryHeaderEnum)\r\n at
System.Runtime.Serialization.Formatters.Binary.__BinaryPar
ser.Run()\r\n at
System.Runtime.Serialization.Formatters.Binary.ObjectReade
r.Deserialize(HeaderHandler handler, __BinaryParser
serParser, Boolean fCheck, IMethodCallMessage
methodCallMessage)\r\n at
System.Runtime.Serialization.Formatters.Binary.BinaryForma
tter.Deserialize(Stream serializationStream,
HeaderHandler handler, Boolean fCheck, IMethodCallMessage
methodCallMessage)\r\n at
System.Runtime.Remoting.Channels.CoreChannel.DeserializeBi
naryRequestMessage(String objectUri, Stream inputStream,
Boolean bStrictBinding, TypeFilterLevel securityLevel)
\r\n at
System.Runtime.Remoting.Channels.BinaryServerFormatterSink
..ProcessMessage(IServerChannelSinkStack sinkStack,
IMessage requestMsg, ITransportHeaders requestHeaders,
Stream requestStream, IMessage& responseMsg,
ITransportHeaders& responseHeaders, Stream&
responseStream)\n\nException rethrown at [0]: \n"
string
stackTraceString
================
_stackTraceString " at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMess
age(IMessage reqMsg, IMessage retMsg)\r\n at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke
(MessageData& msgData, Int32 type)\r\n at
TAM.Data.Common.IPortal.Fetch(Object businessObject,
Object criteria)\r\n at TAM.Framework.Portal.Fetch
(Object businessObject, Object criteria) in
c:\\sourcecode\\tam\\tam.framework\\portal.cs:line 86"
string
_message
========
_message "Cannot find the assembly
TAM.BusinessObjects, Version=1.0.1424.15601,
Culture=neutral, PublicKeyToken=d3e3ed99c018e29a."
string
It keeps wanting to find the assembly that has the
BusinessObjects in even though I'm sending the object as
object type.
Is this a problem with my objects Deserialization or why
does the remoting need my assembly when it can get the
type from the object?
Any comments or help appreciated.
MickD
Mick D
|
|
|
|
|
When you use remoting you have to pass in the EXACT same copy of the class.
|
|
|
|
|
thanks.
ok, I have tried that (using the exact object) and it made no difference, from the exception that I still get. There is stack information against the property "_remoteStackTraceString" which presumably means that the object got to the remote object?? and cannot be unpacked (Deserialized). I cannot remember the sequence that remoting\channels performs when recieving information from another App domain.
Any comments or help appreciated
Mick D
|
|
|
|
|
Are you sure you are recieving the entire class before you try to Deserialize it because the TCP protocol has no bounds checking.
|
|
|
|
|
Hi,
can anybody tell me if what im doing here is correct?
Having 2 DataGrid Controls, one showing data from "ParentTable", the other showing data from "ChildTable", I am trying to synchronize them in a way that when I select a Row in the Child- DataGrid, the Parent- DataGrid should be updated too (dv2 is the DataView of the Parent-DataTable):
private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e)<br />
{<br />
CurrencyManager cm = (CurrencyManager)<br />
dataGrid1.BindingContext[dataGrid1.DataSource ,dataGrid1.DataMember];<br />
<br />
DataRowView drv = (DataRowView)cm.Current; <br />
// Set the RowFilter of the ParentTable-View to reflect changes in Child
<br />
dv2.RowFilter = "VERNR = '"+drv["VERNR"]+"'"; <br />
<br />
}
|
|
|
|
|
First, never concatenate strings like that - you incur serious performance penalties. In actuality, the CLR is creating a string to hold the first part, then creates a second string long enough to hold the first part and the second part, then copies each character from the first and second parts into the new string. Then it repeats this process with a third string. Those other two strings hang around until the GC picks them up. Instead, use String.Concat (string.Concat("VERNR = '", drv["VERNR"] as string, "'") or String.Format (string.Format("VERNR = '{0}'", drv["VERNR"]) ), which uses the StringBuilder internally.
Second, if you're using the code we talked about earlier, then the problem would seem to be in your call to get the CurrencyManager . If you are passing the Relation to the child's DataGrid.DataSource for the parent-child view, then you must pass that (and no DataMember ) when using the BindingContext property. See the docs for the BindingContext , which also mentions this constraint.
Also, you should debug your code and see if you're getting a value for drv["VERNR"] , which you should also cast to a string to be safe, or use the as keyword as I did above to be even more safe (it casts but doesn't throw an exception if the cast fails, it just returns null ).
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Hi,
thanks for the hint on string concatenation, I am new to C# and not quite into the internals yet...
Heath Stewart wrote:
Second, if you're using the code we talked about earlier, then the problem would seem to be in your call to get the CurrencyManager. If you are passing the Relation to the child's DataGrid.DataSource for the parent-child view, then you must pass that (and no DataMember) when using the BindingContext property. See the docs for the BindingContext, which also mentions this constraint
I don't really know if I explained my issue right: The thing is I can't define some Binding where, when selecting some Item in the Child-View, the Parent-View gets updated:
Imagine having a Table with Products where some Column contains a Number being the Foreign-Key to another Table which holds the Vendor Information to any Product with this number as Primary-Key, so browsing through the Products, there should always be the Vendor displayed...
|
|
|
|
|
mgaerber wrote:
I am new to C# and not quite into the internals yet...
String manipulation is tasking in practically any language. Keep what I said in mind when doing anything with strings or other types of buffers.
mgaerber wrote:
I don't really know if I explained my issue right: The thing is I can't define some Binding where, when selecting some Item in the Child-View, the Parent-View gets updated:
You explained it fine, and I gave you one possibility as to what's wrong. The BindingContext contains data- or property-bindings for the control. If you have data-bound your child table to a control, a BindingContext is useful so long as you give it the same DataSource and DataMember that are specified in the control.
What you're doing is essentially right - you're getting a value and filtering the DataView of the parent DataGrid . You really need to debug your code, though - step through it and see if you're getting a value from your DataRowView before applying it to your filter. Stepping through your code and examining the Auto or Locals window should give you some idea of what you can use to get the values you need. I'm sorry I don't have more time to write and test this myself, but learning is the most important part and debugging certainly fosters that.
...but you are on the right track.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|