老兄:这是您要的答案,我已经调试通过了。其中EncryptKey是加密算法,DecodeKey是解密
酸法,您不要研究。
请给分!
procedure TForm1.btWriteClick(Sender: TObject);
var
strPass:String;
arrByte:array of Byte;
i:integer;
begin
{
CREATE PROCEDURE sp_WriteUser
@Name varchar(16),
@Password binary(255)
AS
INSERT INTO Users(Name,Password) VALUES (@Name,@Password)
}
SetLength(arrByte,255);
if Length(edtName.Text)=0 then
begin
edtName.SetFocus;
Exit;
end;
if Length(edtWP.Text)<6 then
begin
edtWP.SelectAll;
edtWP.SetFocus;
Exit;
end;
strPass:=EncryptKey(edtWP.Text);
edtRP.Text:=IntToStr(Length(strPass));
for i:=1 to 255 do
begin
arrByte[i-1]:=Byte(strPass);
end;
adosp.ProcedureName:='sp_WriteUser';
adosp.Parameters.Clear;
adosp.Parameters.CreateParameter('@Name',ftString,pdInput,16,edtName.Text);
adosp.Parameters.CreateParameter('@Password',ftBytes,pdInput,255,arrByte);
adosp.ExecProc;
if dst.Active then
dst.Refresh
else
dst.Open;
end;
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
if dst.Active then
begin
edtName.Text:=dst.FieldByName('Name').AsString;
end;
end;
procedure TForm1.btReadClick(Sender: TObject);
var
strPass:String;
arrByte:array of Byte;
i:Integer;
begin
SetLength(strPass,255);
SetLength(arrByte,255);
adosp.ProcedureName:='sp_ReadUser';
{
CREATE PROCEDURE sp_ReadUser
@Name varchar(16),
@Password binary(255) output
AS
SELECT @Password=(SELECT Password FROM Users WHERE Name=@Name)
}
adosp.Parameters.Clear;
adosp.Parameters.CreateParameter('@Name',ftString,pdInput,16,edtName.Text);
adosp.Parameters.CreateParameter('@Password',ftBytes,pdoutput,255,'');
adosp.ExecProc;
arrByte:=adosp.Parameters.ParamValues['@Password'];
i:=Length(strPass);
edtWP.Text:=IntToStr(i);
strPass:=string(arrByte);
edtRP.Text:=DecodeKey(strPass);
end;