Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Changing User SQL Password
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Changing User SQL Password
Miscellaneous
Thread ID:
00958067
Message ID:
00958067
Views:
48
I thought this was pretty easy, but I can't get it to work. When a user forgets their password, I need to be able to reset it to a new value. So on the user setup dialog, the admin person can enter a new password and set the value to whatever. The problem is that I don't know their old password, so I keep getting a sql error saying the current(old) value is not the same. As you can see in this routine, I create a new connection to sql server logged in as the SA. It's my understanding that the SA account doesn't have to know the old password. Anyway, I'm guessing it's something little that I'm missing and that someone can help point out.

Thanks in advance
***************************************************************************
* Program: ctAdminChangeUserPassword
* Call Example: ctAdminChangeUserPassword('kirk','newpassword')
***************************************************************************
PARAMETERS tcUserName,tcPassword
LOCAL lnSAHandle,lnResult,lcConnString
lnResult=1
tcUserName=ALLTRIM(tcUserName)
tcPassword=ALLTRIM(tcPassWord)
tcPassWord=decrypt(ALLTRIM(tcPassWord),"CQI$$")
= SQLSetProp(0, "displogin", 3)

***************************************************************************
* Create the SA Login
***************************************************************************
saPwd=[mysapassword]
lcSAConnString=[DRIVER={SQL SERVER};SERVER=]+ALLTRIM(gcDataSer)+[;UID=sa;pwd=]+ALLTRIM(saPwd)+[;Network=DBMSSOCN;database=]+ALLTRIM(gcDataDB)+[;App=CTADMIN]
lnSAHandle=SQLSTRINGCONNECT(lcSAConnString)
IF lnSAHandle < 1
	=AERROR(laError)
	SET STEP ON 
	lnResult=-1
ELSE 
	*************************************************************************
	* Set Password
	*************************************************************************
	mNull=NULL
 *>>> This next sqlexec call creates the error, have tried passing 3 parameters with null as first same effect
 *>>> "Connety error: [Microsoft][SQL Server]Old (current) password incorrect for user. The password was not changed."  
	IF SQLEXEC(lnSAHandle,[exec sp_password ?tcPassword,?tcUserName])<1
		=SQLERROR(program(),program(),transform(lineno()),"ctAdminChangeUserPassword.prg")
		lnResult=-1
	ENDIF 
	***************************************************************************
	* Release the Admin Handle
	***************************************************************************
	=SQLDISCONNECT(lnSAHandle)
	RELEASE lnSAHandle
ENDIF 
RETURN (lnResult)
Next
Reply
Map
View

Click here to load this message in the networking platform