benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 9163421e-11d8-5de7-ae36-1921762cbd25

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import hashlib
import binascii

def task_func(salt, cursor):
    """
    Updates the passwords in a user table of an SQLite database by hashing them with SHA256, 
    using a provided salt. The function directly modifies the database via the given cursor.

    Parameters:
    - salt (str): The salt value to be appended to each password before hashing.
    - cursor (sqlite3.Cursor): A cursor object through which SQL commands are executed.

    Returns:
    - int: The number of users whose passwords were successfully updated.

    Requirements:
    - hashlib
    - binascii

    Raises:
    TypeError if the salt is not a string
    
    Example:
    >>> conn = sqlite3.connect('sample.db')
    >>> cursor = conn.cursor()
    >>> num_updated = task_func('mysalt', cursor)
    >>> print(num_updated)
    5
    """

instruct prompt

Updates the passwords in a user table of an SQLite database by hashing them with SHA256, using a provided salt. The function directly modifies the database via the given cursor.
The function should raise the exception for: TypeError if the salt is not a string
The function should output with:
    int: The number of users whose passwords were successfully updated.
You should write self-contained code starting with:

Code

import hashlib
import binascii
def task_func(salt, cursor):

code prompt

Code

import hashlib
import binascii
def task_func(salt, cursor):

entry point

task_func

libs

  • hashlib
  • binascii

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import