|
You're better off not using System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile as you'll have to include the System.Web reference in you're project. Try using the SHA1 hash algorithm instead:
<br />
Imports System.Security.Cryptography<br />
Imports System.Text<br />
<br />
Public Shared Function GeneratePasswordHash(ByVal password As String) As String<br />
Dim pwdData As Byte() = Encoding.UTF8.GetBytes(password)<br />
Dim sha As SHA1 = New SHA1Managed<br />
<br />
Dim hashData As Byte() = sha.ComputeHash(pwdData)<br />
sha.Clear()<br />
<br />
Return Convert.ToBase64String(hashData)<br />
Return Encoding.UTF8.GetString(hashData)<br />
<br />
End Function<br />
modified on Saturday, April 19, 2008 5:30 AM
|
|
|
|
|
Thank U so much Rob Smiley.
I try that.
|
|
|
|
|
Rob Smiley wrote: Return Encoding.UTF8.GetString(hashData)
That doesn't work. The hash data is not an utf-8 encoded string, so you can't decode it into a string.
If you want the data as a string, you can use base 64:
Return Convert.ToBase64String(hashData)
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Yeah, you're right. Probably should have tested this before posting
"An eye for an eye only ends up making the whole world blind"
|
|
|
|
|
b4 this my prgm running ok.. and i don't do any editing. after a few days, when i try to add data in my databse, there was a msg "runtime error" about my web.config.. my customErrors mode="off", so i change my mode to RemoteOnly.. but another problem come out. it says that "String or binary data would be truncated. The statement has been terminated" and then the source error is :
Line 623: cmd.Connection.Open()
Line 624: cmd.ExecuteNonQuery() <-- this line r in red colour
Line 625: cmd.Connection.Close()
this happen after i key in my data and i want to add the data to my database... helpp me pls...
|
|
|
|
|
I'm sorry, but that's not really all that helpful. This tells me that:
1 - you want to run some SQL
2 - if it ran some data somewhere would be truncated
3 - it throws an error
I can't tell you more than that, and I'd hope you could work that out for yourself. I'd say this means one of your parameters is too big, which in turn makes me syspect that you're string mashing SQL, which probably means your code is open to all sorts of attacks. But, hard to say if you are not showing the pertinent code.
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 )
|
|
|
|
|
|
this is my coding.
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim _kod As String
Dim Pemanggil As String
Dim Negeri As String
Dim run_no As String
Pemanggil = TextBox10.Text.Trim
Negeri = TextBox4.Text.Trim
If Kod.Text.Length > 0 And Nama.Text.Length > 0 And TextBox4.Text.Length > 0 And TextBox10.Text.Length > 0 And No_Tel.Text.Length > 0 And Masalah.Text.Length > 0 And Penyelesaian.Text.Length > 0 And TextBox9.Text.Length > 0 Then
Dim myConn As New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
Dim MySQL As String = "INSERT INTO Senarai_Log(docNo,Tarikh,Kod_Koop,Nama_Koop,Nama_Koop1,Negeri,Nama,No_Tel,Masalah,Penyelesaian,Tindakan) Values (@docNo,@Tarikh,@Kod_Koop,@Nama_Koop,@Nama_Koop1,@Negeri,@Nama,@No_Tel,@Masalah,@Penyelesaian,@Tindakan)"
Dim cmd As SqlCommand = New SqlCommand(MySQL, myConn)
cmd.Parameters.Add(New SqlParameter("@Tarikh", SqlDbType.NVarChar, 250))
cmd.Parameters("@Tarikh").Value = System.DateTime.Now.Date
cmd.Parameters.Add(New SqlParameter("@Kod_Koop", SqlDbType.NVarChar, 250))
cmd.Parameters("@Kod_Koop").Value = Kod.Text.Trim
cmd.Parameters.Add(New SqlParameter("@Nama_Koop", SqlDbType.NVarChar, 250))
cmd.Parameters("@Nama_Koop").Value = Nama.Text.Trim
cmd.Parameters.Add(New SqlParameter("@Nama_Koop1", SqlDbType.NVarChar, 250))
cmd.Parameters("@Nama_Koop1").Value = Nama1.Text.Trim
cmd.Parameters.Add(New SqlParameter("@Negeri", SqlDbType.NVarChar, 250))
cmd.Parameters("@Negeri").Value = Negeri
cmd.Parameters.Add(New SqlParameter("@No_Tel", SqlDbType.Char, 50))
cmd.Parameters("@No_Tel").Value = No_Tel.Text.Trim
cmd.Parameters.Add(New SqlParameter("@Masalah", SqlDbType.Char, 250))
cmd.Parameters("@Masalah").Value = Masalah.Text.Trim
cmd.Parameters.Add(New SqlParameter("@Penyelesaian", SqlDbType.NVarChar, 250))
cmd.Parameters("@Penyelesaian").Value = Penyelesaian.Text.Trim
cmd.Parameters.Add(New SqlParameter("@Tindakan", SqlDbType.Char, 50))
cmd.Parameters("@Tindakan").Value = TextBox9.Text.Trim
cmd.Parameters.Add(New SqlParameter("@Nama", SqlDbType.Char, 50))
cmd.Parameters("@Nama").Value = Pemanggil
cmd.Parameters.Add(New SqlParameter("@docNo", SqlDbType.NVarChar, 50))
cmd.Parameters("@docNo").Value = System.DateTime.Now.ToString("yyyyMMdd") & Kod.Text & GetRunNo().ToString("D4")
cmd.Connection.Open()
cmd.ExecuteNonQuery()
cmd.Connection.Close()
Label3.Text = "MAKLUMAT TELAH DISIMPAN."
Label3.Visible = True
Else
Label3.Text = "SILA PENUHKAN MEDAN KOSONG."
Label3.Visible = True
End If
Clear()
End Sub
this button suppose to add all the data that i've key in, put in table "Senarai_Log". i have try this prgm 10 time and there's nothing wrong with it. but today when i try to add the data, the error msg about the web.config appear, when i change the customerrors mode, the error for string and binary msg appear.
|
|
|
|
|
Check the lengths of the parameters/ values against the corresponding database columns. Thats usually the problem, data longer than the column supports.
Bob
Ashfield Consultants Ltd
|
|
|
|
|
I never specify lengths like this, I just add the parameters directly and let the framework, work it out for me.
I would suggest that it would be great for you to do some study, you may want to read the article I link to in my sig, it explains how best to get help when you have an error message you cannot understand.
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 )
|
|
|
|
|
thank you. i have found the problem. the article really help.
|
|
|
|
|
I have an application that I have been working on for a while now and suddenly something that was working fine just fails - the global module!
The items I have been tweaking lately are not related at all to the global module and I had been running and rerunning the app over and over when one time it just stopped - with that error. It fails on the first attempt to access a public routine to create the DB connection , or other variables.
Does anyone know what could have caused it - I mean I honestly made no changes involving the module at all!
I'd show source code, but I can't think of anything relevant to show.
jooooo
|
|
|
|
|
What error?? Is this a Public Module or Public Class exposing Public Shared methods??
Try dropping the module or class file from the project and readding it.
|
|
|
|
|
Thanks Dave for quick reply ..
it's a public Module ...
i put all public variables and methods >> it's ok and work as good ..
then I installed vb.net 2008 ...
after that when run project under 2005 or 2008 this error is happened when calling any variable or method from the module ...
>> after some search one of my friends told me that , this error happened when call method before module is initialized..
really i'm confused .. the project was running ok .....
jooooo
|
|
|
|
|
There is no such thing as "initializing a module". Your code may require something to be setup, but a module (not your code) doesn't need anything to initialize.
|
|
|
|
|
Does a dataset retain the original value for each field after it has been changed. For example is I have a field called Name with is set to equal 'Fred' then I change it to equal 'Joe', is there away of getting the orginal value from the dataset, or do I have to store the original value else where?
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
Yes, each DataRow object maintains a DataRowVersion of itsself. The orignal value is maintained so long as the DataRow (or parent table) does not have it's AcceptChanges, RejectsChanges, or any other method that refreshes the dataset, called. You can get at it something like:
Dim originalValue As Integer = Convert.ToInt32(MyDataTable.Rows(0).Item(someColumnNumber, DataRowVersion.Original))
Dim newValue As Integer = Convert.ToInt32(MyDataTable.Rows(0).Item(someColumnNumber, DataRowVersion.Current))
|
|
|
|
|
Thanks Dave, I knew I had dreamt it. Thanks again, you really are a Super Guru, aren't you!?
Steve Jowett
-------------------------
It is offen dangerous to try and see someone else's point of view, without proper training. Douglas Adams (Mostly Harmless)
|
|
|
|
|
Steven J Jowett wrote: you really are a Super Guru, aren't you!?
Not really, but my Google-Fu is very strong.
|
|
|
|
|
hy everyone!
i know my question is of topic but maybe someone has an idea why this problem occures:
I do have a macro which parses files. when finished i want to move the file to a different directory (either the one, where well parsed files are put into or in the one where bad parsed files are put into).
therefor i have to use the movefile and deletefile.
because my macro first checks, if there is already and (old) copy of the file, if so then delete it and replace it with the new one. if not then i simply copy it to the destination file.
therefor i programmed
Function DeleteandMoveFile(ByVal dest As String, ByVal source As String, ByVal filename As String) As Boolean
Dim filesys As Object
DeleteandMoveFile = TRUE 'just a dummy operation
Set filesys = CreateObject("Scripting.FileSystemObject")
'Check if File exists in destinationpath then delete it
If filesys.FileExists(dest & filename) Then
If filesys.DeleteFile(dest & filename)then
'MsgBox "file deleted successfully
Else
'MsgBox "couldn't delete file"
Application.WriteEventLog "macro", "couldn't delete file",5
End If
End If
' Check if file exists in source path then move it
If filesys.FileExists(source & filename) Then
If filesys.MoveFile(source & filename, dest)
'MsgBox "file moved"
Else
Application.WriteEventLog "macro", "file couldn't be moved!",5
End If
Else
Application.WriteEventLog "macro", "file does not exist!" ,5
End If
Set filesys = Nothing
End Function
Looks fine, doesn't it? Well the macro does exactly what I want it to, but it also writes the error messages into eventlog. Meaning it does the if statements but the steps directly to the error message and continues operating. As if I also added the error message to the if statement.
Does anyone of you have an idea? Does Windows somehow have a handle or something on the file which causes an exception when moving or deleting??
If it doesn't work, then it would be "ok" for me, but remember: The macro does what I want it to but throws the error messages as well (seems to be in if and else during the same loop!).
Maybe anyone of you could help me please!
thanks.
Stephan.
|
|
|
|
|
Simpler idea. First, check if the source file exists. Then, if it does, just copy the file from the source to the destination, overwriting the destination if the same filename exists. That way, you don't have to care if the destination exists, just to delete the thing anyway.
Now, on to your actual problem. Since MoveFile and DeleteFile do NOT return any kind of value, I think your actually checking the FSO object instance being Nothing, which will return False, and hence, log an error message.
To prevent weird problems like this, I usually don't call methods on objects inside conditional expressions. I usually assign return values to vairables and use those variables in the expressions instead. This allows for additional checking of return values, such as valid objects and values within expected ranges.
|
|
|
|
|
thanks for the hint!
unfortunatly i encountered another problem:
sometimes this statment seems to return "false" even if the file is located at the specified folder, any ideas?
<br />
If filesys.FileExists(source & filename) Then <br />
let's say source is "C:\myfiles\todo\"
and filename is "myfile.txt"
then the whole string is "C:\myfiles\todo\myfile.txt". (in debugmode the contence of the variables is correct (i already checked that).
i also checked, the file is at the specified path, so this statement should return true, but it doesn't and I have no idea why.
are there some circumstances, when this statement returns a wrong result?
could it be, there is a non printable sign somewhere inbetween (a string endsign for example)??
because when I debug the code then it stops at this line (breakpoint) and when I do a step forward, the whole if branch is skipped and the code continues either at the else part or (if there is none) below the whole if .. endif statment.
did anyone of you encounter the same problem? why does the exists statement return false, if the file is there??
if i am able to solve this problem, my script is finished and should be working correctly
thanks.
stephan.
|
|
|
|
|
I've never ran into the problem myself, nor have I heard of an instance when the function returned the wrong result.
But, I've already told you why I don't embed calls to methods inside an IF statements conditional expression.
|
|
|
|
|
i guess i should try to check the string in a variable if it is correct and then check the result in a variable as well.
well, strange things happen in my macro but i hope i will solve them all soon
|
|
|
|
|
I have encountered a similar problem whan the FOLDER did not exist - in my case i had a path like c\work\temp - i.e. I missed the : after the drive.
Could a \ be missing in part of your path?
Bob
Ashfield Consultants Ltd
|
|
|
|
|