|
thanks, I will try that
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
i'm sorry but i'm a bit lost here, the function you sent me sends back a hash of the password, but it doesn't use the salt value I give in the functions I posted...my situation is that I am building a web application but I would like to have a windows form to be able to change the admin password in the database and then in the web site, I use the functions I posted to check the username and password of the admin by hashing the password given using the SALT key.
thanks
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
It's sample code, not a complete solution. Just concatenate the salt as you did before calling the FormsAuthentication.HashPasswordForStoringInConfigFile method.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
yes I'm sorry, how stupid of me...it's nearing 11pm here, ok I got it to compile now, I will test that tomorrow and see if it works in parallel with the web form and gives the same results. thanks again
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
It's MD5, a hashing standard. So long as you're salting the value and use the same characters (case-sensitive) for the value to hash, it will work. If you're taking this from user input, you might consider trimming the strings on either side before hashing, unless you wanted to accept beginning and trailing whitespace.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
ok, done
I have one question about this:
<br />
StringBuilder sb = new StringBuilder(cipher.Length * 2);
for (int i=0; i < cipher.Length; i++)
sb.Append(cipher[i].ToString("x2")); <br />
what does it do exactly? I am mainly asking about this ToString("x2")
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
See the documentation for Byte.ToString(String) . It formats the byte as hex using 2 characters (so that a byte is always formatted as two chars, even if less than 127). If you don't, your MD5 is invalid since the hash must be 128 bits, or 32 hex characters (representing 16 bytes).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
oh ok, I understand now, thanks.
by the way, great Dusk at Sea World photo, I love photography and this picture is very good
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning."
--Rich Cook
|
|
|
|
|
i want to built a socket program like a chating program in yahoo messanger.I want to know how i treat both modules(means is there are two threads reading & writing thread at both modules or something else?if u have some article about this ,tell me or give me some hints.
mughalali
|
|
|
|
|
There are hundreds if not thousands of examples of chat applications out there and even right here on CodeProject. Just http://www.google.com[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i want to built a socket program like a chating program in yahoo messanger.I want to know how i treat both modules(means is there are two threads reading & writing thread at both modules or something else?if u have some article about this ,tell me or give me some hints.
mughalali
|
|
|
|
|
I have a problem stopping the server process. Everything seems fine when i stop my multithreaded server, no exceptions when i shut down the application. But the server program wont stop executing. I cant find any more threads that i have forgot to abort. Still if i try to abort the CurrentThread in the end of the program i get an AbortException that cant be handled by the application. Is there something else i can try?
Michelangelo
|
|
|
|
|
Without seeing any code, all I can tell you is that to handle the seemingly uncatchable ThreadAbortException , handle the current AppDomain's AppDomain.UnhandledException event to catch ThreadAbortException s (or any others you might want caught).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi,
I presume your server is using a thread which continually listens on a port by running it on a thread.
Currently when you close your program down the lightweight process (the thread) continues to be executed.
In the applications "closing" event you need to ensure all threads running are interrupted and cleaned up.
Dont use the STOP method as it is very bad.. you could end up with part written data for the instance of the program.
Theres a pretty complete guide here on threads:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchusingthreads.asp[^]
Which is worth a glance, but for the quick solution do this in the closing event for the main form/application:
threadinstance.Interrupt();
|
|
|
|
|
The threads you have created may be foreground threads. These threads will keep the process running until they stop. Try setting the Thread.IsBackground property to true. Once all foreground threads have stopped executing the runtime will abort all background threads automatically.
|
|
|
|
|
I'm calling one of my own dll functions in an unmanaged (C++) dll from a managed (C#) dll. I am passing an array of structures, as an [In, Out] parameter, 512 elements long. It enters the function okay, does the necessary work, then on return from the function, i.e. when you step out of the scope of the unmanaged function in the debugger, the managed side catches a System.OutOfMemoryException with no additional info.
The C++ Structure is:
<br />
struct AudioFormat<br />
{<br />
unsigned long type;<br />
<br />
wchar_t name[MAXCHARS];<br />
<br />
unsigned short formatTag;<br />
unsigned short channelCount;<br />
unsigned long samplesPerSec;<br />
unsigned long avgBytesPerSec;<br />
unsigned short blockAlign;<br />
unsigned short bitsPerSample;<br />
unsigned short additionalBytes;<br />
};<br />
The C# structure is:
<br />
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]<br />
public struct DataFormat<br />
{<br />
public MajorDataType majorType;
<br />
public string name;<br />
<br />
public ushort formatTag;<br />
public ushort channelCount;<br />
public uint samplesPerSec;<br />
public uint avgBytesPerSec;<br />
public ushort blockAlign;<br />
public ushort bitsPerSample;<br />
public ushort additionalBytes;<br />
}<br />
The C++ function declaration is:
<br />
void DSDataTranslator::FilterGraph::AllAvailableFormats(AudioFormat *availableFormatsParam, unsigned long &availableFormatsLenParam)<br />
The C# function declaration is:
<br />
[DllImport("DSDataTranslator.dll", EntryPoint = "?AllAvailableFormats@FilterGraph@DSDataTranslator@@SAXPAUAudioFormat@2@AAK@Z", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]<br />
private static extern void AllAvailableFormats([In, Out] DataFormat[] availableFormats, ref uint availableFormatsCount);<br />
The C# call is:
<br />
uint maxCount = (uint)DataTranslatorConsts.MAXFORMATS;
<br />
DataFormat[] availableAudioFormats = new DataFormat[maxCount];<br />
<br />
for(uint index = 0; index < availableAudioFormats.Length; index++)<br />
{<br />
availableAudioFormats[index].name = "";<br />
}<br />
<br />
try<br />
{<br />
AllAvailableFormats(availableAudioFormats, ref maxCount);<br />
}<br />
catch(System.NullReferenceException e)<br />
{<br />
Debug.Assert(false);<br />
}<br />
catch(System.OutOfMemoryException e)<br />
{<br />
Debug.Assert(false);<br />
}<br />
Can anybody please help as I cannot for the life of me figure out what the issue is here? I certainly know that in the catch block if I examined the contents of availableAudioFormats it's garbage, whereas before the call everything had been intialized to 0. If anymore info is required, please ask.
|
|
|
|
|
|
I've looked at the managed extensions for C++ required to instantiate structs or classes in C#, I believe you use __gc, but unfortunately the method is declared as static in the .h file so it's not required and hence no joy there. Thanks for the reply though, and I do intend to try using __gc later on in my development. In fact I'll give it a go anyway to see what happens. Also, you might be interested to know that if I increase the array size to 4096 (rather large, I know but it is to cover all the different possible codecs and formats that a system might have installed) the exception caught is NullReferenceException.
|
|
|
|
|
The problem has nothing to do with Managed C++ extensions since you're P/Invoking the method from C#. I'm not sure what you were trying to get at, really.
If the native method is declared as static, then off-hand I really don't see what's wrong. Your declarations look correct, except that you're not declaring a fixed size for your string field. See the MarshalAsAttribute documentation for different ways of doing this, like using the SizeConst and setting that to the value of MAXCHARS you used in your native declaration.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Sorry, thought I'd read somewhere on MSDN that you can easily include classes defined in C++ by declaring them with the __gc managed extension, haven't really looked into it though.
I've already tried the [MarshalAs(UnmanagedType.LPWStr, SizeConst = MAXCHARS)] attribute and again there was no rejoicing. In fact I think I've just about tried everything, including adjusting my seat position and the way I tie my shoe laces but none of it seems to work... maybe a low carb diet might work... I'm really grasping at the proverbial straw here. The only way I see out of this at the moment is to pass in arrays of the same size, one for each variable in the structure that I need to set. That's really filthy, I'm going to wash my mouth out with carbolic soap, but if it works, it works.
|
|
|
|
|
You can, I just don't know why you brought it up in this discussion. If you declared your struct as a managed struct, then you wouldn't need to P/Invoke anything anyway.
One thing you could try is to fix the memory address of the array before passing it, also changing your first param to IntPtr , something like this:
GCHandle handle = GCHandle.Alloc(myArray);
MyMethod(handle.AddrOfPinnedObject(), ...);
handle.Free(); This makes sure that the GC doesn't move it while in use, which can lead to all sorts of problems.
I do a lot of unmanaged interop and frankly have never had this problem, so I'm sorry I can't be of more help. Believe me, it's bugging me now, too.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
More of an aside, in relation to your mention of instance methods, but it seems to have led to a possible solution by avoiding the use of P\Invoke by using the __gc declaration. In fact, with it being my own structure, there's no reason not to. Thanks again, I'll try this in the morning (this is the UK and it's nearly 23:00 and I've been staring at the screen for so long the walls of my house are covered in text). I'll update you to let you know how it goes but I've got a feeling it'll work.
|
|
|
|
|
Hello Heath,
after some time away and quite a bit of coding to wrap up my dll in C++ managed extension stuff I have perfect interoperability. The managed extensions make interop virtually seemless and the P/Invoke stuff more or less pointless for C++ stuff unless your only passing simple datatypes. Thanks for your help.
Luke
|
|
|
|
|
I'm still suffering from flickering problems and glitchy transparent corners (they show the background, not the controls underneath).
I think the solution to both problems could be to make a buffered bitmap. But i've no idea how to buffer the Theme as it's drawn directly to the screen.
I played around with attempting to use the bitmap graphics object to create an hDC handle, but it didn't work, i just got black.
Any ideas what I could do?
Cata
|
|
|
|
|
You can enable double-buffering for a control easily by calling the following in your constructor:
SetStyle(ControlStyles.AllPaintingInWmPaint |
ControlStyles.DoubleBuffer | ControlStyles.UserPaint, true); This tells the CLR to call OnPaint in a separate thread to draw to an off-screen bitmap. When the painting is done, the image is flipped to the device context. Or at least, it's something close that that. This saves you from having to swap everything yourself and from using an incompatible bitmap if not created correctly.
Microsoft MVP, Visual C#
My Articles
|
|
|
|